6_2 Rail (UVa514)

Source: Internet
Author: User

There is a famous railway station in a city called "the City of stacking". Due to the constraints of the terrain and the relationship between funds, the railway station and the only railway look like:

Now the train is coming from a direction, it is scheduled to depart from the b direction. The train has n carriages (n <=1000), and the carriages are numbered 1 to n in turn. You can assume that each compartment can be separated from the other carriages before the pit stop, or you can leave the station separately and go to the rail on the B direction. You can also assume that at any time the train station can accommodate all the carriages. But once a car comes in, it can no longer return to the A-direction rail, and once it leaves the station heading B, it cannot return to the station.


Now your task is to write a program that determines whether the train can be arranged in a specific arrangement on the rails in the B direction.

Input
The input contains multiple sets of test data. The first column of each set of test data has 1 integer n, meaning as described above. For this group of test data there are next 0 to several tests, one for each column, with n integers for each column, and the content is any permutation of 1,2,......,n. When encountering a column that contains only one 0, the end of the test data on behalf of the group.
N=0 represents the input end, please refer to sample input.
Output
For each test of each set of test data, it is possible to output any permutation of the 1,2,......,n. If possible, output Yes and output No if it is not possible.
Please also empty a column after each set of test data. Please refer to the sample Output

Sample Input

51 2 3 4 55 4 3 2 15 4 1 2 3074 5 3 7 6 2 100

Sample Output

Yesyesnoyes

6_2 Rail (UVa514)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.