首页 > ACM题库 > HDU-杭电 > hdu 4806 Circular Lamps待解决[解题报告]C++
2015
09-18

hdu 4806 Circular Lamps待解决[解题报告]C++

Circular Lamps

问题描述 :

The circular roundabout of 2nd road is an important traffic junction in Nanjing University of Science and Technology. To celebrate the 60th anniversary, the school officer decides to build some lamps with digital shape surrounding the circular roundabout.
There are 2N lamps to build. Lamps have the shape of digits, ranging from 1 to 2N. Specially, lamps will be built as a whole which can’t be split into single numbers. For example, lamp 19 can’t be split into lamp 1 and lamp 9. Since the roundabout is circular, the last lamp is next to the first lamp. Unfortunately, due to the carelessness of the construction team, some lamps are placed in the wrong position. Since the construction team is now
absent after finishing their work, we could only correct the order of lamps by ourselves. After rearrangement, the lamp with the shape i (1 <= i <= 2N) is expected to be placed on the i-th position. In other words, the final permutation should be 1, 2, … , 2N. Because of the large volume of the lamps, we have only two ways to adjust the order

1) Reverse the consecutive 4 lamps starting from the position x, denotes as (1 x). For example:
(1 4): 1 2 3 [4 5 6 7] 8 -> 1 2 3 [7 6 5 4] 8
or
(1 6): 1] 2 3 4 5 [6 7 8 -> 6] 2 3 4 5 [1 8 7
where ‘[’ stands for the start position, and ‘]’ stands for the end position respectively.
2) Shift all lamps to the left by x positions, denotes as (2 x). For example:
(2 4): 1 2 3 4 5 6 7 8 -> 5 6 7 8 1 2 3 4
or
(2 7): 1 2 3 4 5 6 7 8 -> 8 1 2 3 4 5 6 7

The data guarantees the existence of a valid adjustment sequence. Also the case where all lamps are already placed correctly will not exist in the input.

Your task is to generate a valid adjustment sequence that all lamps are put on the correct position.

输入:

There are several test cases, please process till EOF.
Each test case starts with a line containing one integers N(2 <= N <= 30). The next line contains 2N different integers, the i-th number Ai denotes that the shape of the i-th lamp is Ai(1 <= Ai <= 2N).

输出:

There are several test cases, please process till EOF.
Each test case starts with a line containing one integers N(2 <= N <= 30). The next line contains 2N different integers, the i-th number Ai denotes that the shape of the i-th lamp is Ai(1 <= Ai <= 2N).

样例输入:

4
6 5 4 3 2 1 8 7
4
4 5 1 2 3 6 7 8
4
7 8 4 3 2 1 5 6

样例输出:

2
1 2
1 6
2
1 2
1 1
2
1 3
2 2