#P14770. [ICPC 2024 Seoul R] Pair Sorting
[ICPC 2024 Seoul R] Pair Sorting
题目描述
There are bins arranged in a row and balls on the ground. The balls are numbered from 1 to and there are exactly two balls numbered , for each , . Also, for , the -th bin is denoted by and each bin can contain at most two balls. Initially, the bin contains both of ball 's, for . See the Figure F.1 below for the initial configuration of bins.
:::align{center}

Figure F.1. The initial configuration of bins :::
You can swap two balls only from adjacent bins, which implies one swap operation. Note the bin is not a stack and for adjacent bins and , you can swap the one of two balls in and the one in . See the Figure F.2 below. The figure represents two swap operations.
:::align{center}

Figure F.2. The swap operations between adjacent bins :::
Through these swap operations, you should sort the balls. As a result of the sorting, the bin must contain the both of ball 's, for . In particular, the total number of swap operations should be no more than , when is given as a function of , especially, .
Given bins and balls, write a program to find a sorting method of balls such that the total number of swap operations is no more than .
输入格式
Your program is to read from standard input. The input consists of exactly one line. The line contains an integer (), representing that there are bins and balls.
输出格式
Your program is to write to standard output. Let be the total number of swap operations in your sorting method for the input. Print exactly lines. The first line contains . Each of the following lines contains three integers and , representing one swap operation between the ball in the bin and the ball in , where and . The swap operations in your sorting method should be printed in order, one per line. The number must satisfy that .
3
6
1 3 2
2 3 1
1 2 1
1 3 2
2 3 1
1 2 1
3
5
1 3 2
2 3 1
1 3 1
2 3 1
1 2 1