编程介的小学生 2019-08-27 21:46 采纳率: 20.5%
浏览 108

Circular Lamps怎么程序来实现啊

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
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

Sample Output
2
1 2
1 6
2
1 2
1 1
2
1 3
2 2

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python