#P14770. [ICPC 2024 Seoul R] Pair Sorting

[ICPC 2024 Seoul R] Pair Sorting

题目描述

There are n n bins arranged in a row and 2n 2n balls on the ground. The balls are numbered from 1 to n n and there are exactly two balls numbered i i , for each i i , 1in 1 \leq i \leq n . Also, for 1in 1 \leq i \leq n , the i i -th bin is denoted by Bi B_i and each bin Bi B_i can contain at most two balls. Initially, the bin Bi B_i contains both of ball n+1i n+1-i 's, for 1in 1 \leq i \leq n . 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 Bi B_i and Bi+1 B_{i+1} , you can swap the one of two balls in Bi B_i and the one in Bi+1 B_{i+1} . 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 Bi B_i must contain the both of ball i i 's, for 1in 1 \leq i \leq n . In particular, the total number of swap operations should be no more than Bound \text{Bound} , when Bound \text{Bound} is given as a function of n n , especially, Bound=0.7n2 \text{Bound} = 0.7n^2 .

Given n n bins and 2n 2n balls, write a program to find a sorting method of balls such that the total number of swap operations is no more than Bound=0.7n2 \text{Bound} = 0.7n^2 .

输入格式

Your program is to read from standard input. The input consists of exactly one line. The line contains an integer n n (3n100 3 \leq n \leq 100 ), representing that there are n n bins and 2n 2n balls.

输出格式

Your program is to write to standard output. Let S S be the total number of swap operations in your sorting method for the input. Print exactly S+1 S+1 lines. The first line contains S S . Each of the following S S lines contains three integers j,a, j, a, and b b , representing one swap operation between the ball a a in the bin Bj B_j and the ball b b in Bj+1 B_{j+1} , where 1jn1 1 \leq j \leq n-1 and 1a,bn 1 \leq a, b \leq n . The swap operations in your sorting method should be printed in order, one per line. The number S S must satisfy that S0.7n2 S \leq 0.7n^2 .

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