-->
当前位置:首页 > 题库 > 正文内容

PROGRAMMING:Train rearrangement

Luz4年前 (2021-05-10)题库411
The structure of the train dispatching track of the railway station is as follows: (exit) 9 8 7 6 5 4 3 2 1 < = = =...... < = = = = 8 4 2 5 3 9 1 6 7 (entrance) two ends are respectively an entrance track and an exit track, between which there may be N parallel tracks. Each train can choose any track to enter the queue from the entrance to facilitate the final orderly exit. In the previous example, there are nine trains waiting at the entrance in the order of {8, 4, 2, 5, 3, 9, 1, 6, 7}. If they are required to leave from the exit in descending order, at least how many parallel tracks are needed for dispatching? What's the situation of cars in each queue after dispatching?
**Input format:**
The first line of input gives an integer n (2 ≤ n ≤ 99), and the next line gives a rearrangement of integer sequence numbers from 1 to n. Numbers are separated by spaces.
**Output format:**
The first line outputs the elements in the queue where No. 1 car is located (the number of cars is separated by a space). Note that during scheduling, cars only enter the queue to wait, not leave the queue.
In the second line, output the minimum number of auxiliary tracks (queues) needed to rearrange the input trains in descending order.
###Input example:
```in
nine
8 4 2 5 3 9 1 6 7
```
###Output example:
```out
8 4 2 1
four
```







answer:If there is no answer, please comment

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。