当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4806:Circular Lamps

Special Judge 特殊评判
题目描述
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).
输出解释
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.
输入样例
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
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4806

最后修改于 2020-10-25T23:17:03+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 32768/32768K(Java/Others)