|
||||||||||
Circular LampsTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 181 Accepted Submission(s): 23 Special Judge Problem Description 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. Input 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). Output For each test case, the first line of the output should contain a single integer S <= 400000, denoting the number of swap operations you need to perform. Each of the following S lines should consist of two integers. The first one may be 1 or 2, indicating the type of swap operations. For the first type, the second number is the start position of the operation, and for the second type, the second number is the positions you need to shift. In both cases, the second number should be ranged between 1 and 2N. If there are multiple possible solutions satisfying the conditions above, any one will be accepted. Please don’t print extra empty lines, spaces and other irrelevant characters. Sample Input
Sample Output
Source | ||||||||||
|