22837_DinnerTime

2022-5-16 18:23| 发布者: Hocassian| 查看: 21| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-895075770500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22837

Title

Dinner Time

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22837

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Farmer John has N (3 ≤ N ≤ 50000) cows, each branded with a unique serial number in the range 1..N. Each night, they line up for dinner by forming a line(queue) with the cows in a relatively random order. Any given ordering can be expressed as an N digit number in base N.

    Farmer John doesn't like random ordering. He wants the cows to line up in a way such that the number that represents the ordering is minimized. The cows, however, don't like do be told exactly what to do all the time.

    FJ and the cows have reached a compromise: the cows will line up and then rearrange themselves into a certain new order that minimizes the ordering's representation. The trick is that each serial number in the new ordering can differ by no more than 1 from the serial number that used to occupy that slot.

    If 8 cows lined up like this: 8 5 7 3 6 4 2 1

    Then the new ordering would be: 7 4 8 2 6 5 3 1

    because:

    * No slot in the second list contains a digit that differs from the digit above by more than 1 (sometimes the ference is 0)

    * This is the smallest number that can be obtained using the rules.

    Your job is to tell FJ the new ordering of cows so he can ensure they are lined up properly.

    输入

    * Line 1: One line with a single integer: N

    * Lines 2..N+1: Each line contains a single integer that is the serial number of a cow in the respective slot. The left-hand cow is given first.

    输出

    Description

    Farmer John has N (3 ≤ N ≤ 50000) cows, each branded with a unique serial number in the range 1..N. Each night, they line up for dinner by forming a line(queue) with the cows in a relatively random order. Any given ordering can be expressed as an N digit number in base N.

    Farmer John doesn't like random ordering. He wants the cows to line up in a way such that the number that represents the ordering is minimized. The cows, however, don't like do be told exactly what to do all the time.

    FJ and the cows have reached a compromise: the cows will line up and then rearrange themselves into a certain new order that minimizes the ordering's representation. The trick is that each serial number in the new ordering can differ by no more than 1 from the serial number that used to occupy that slot.

    If 8 cows lined up like this: 8 5 7 3 6 4 2 1

    Then the new ordering would be: 7 4 8 2 6 5 3 1

    because:

    * No slot in the second list contains a digit that differs from the digit above by more than 1 (sometimes the ference is 0)

    * This is the smallest number that can be obtained using the rules.

    Your job is to tell FJ the new ordering of cows so he can ensure they are lined up properly.

    Input

    * Line 1: One line with a single integer: N

    * Lines 2..N+1: Each line contains a single integer that is the serial number of a cow in the respective slot. The left-hand cow is given first.

    Output

    N lines, each with a single integer that tells which cow belongs in the respective slot. The first output line should contain the serial number of the cow in the left-hand slot (and so on).

    Sample Input

    8
    8
    5
    7
    3
    6
    4
    2
    1

    Sample Output

    7
    4
    8
    2
    6
    5
    3
    1

    Source

    样例输入

    8
    8
    5
    7
    3
    6
    4
    2
    1

    样例输出

    7
    4
    8
    2
    6
    5
    3
    1

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部