#8. Life Will Change
Life Will Change
Problem Statement
Given a permutation of length , , you can perform an operation where you swap two elements and , with .
Your task is to sort the permutation in ascending order in at most operations. You need to output a sequence of operations that achieves this.
Input
The first line contains an integer , the length of the permutation .
The second line contains integers , representing the given permutation. It is guaranteed that each integer from to appears exactly once.
Output
On the first line, output an integer , the number of operations required.
In the following lines, output two integers and per line, indicating a swap between and .
Example
Input
5
3 4 1 5 2
Output
3
1 3
2 4
5 2
Constraints
- For all inputs, .
- There may be multiple valid solutions; you only need to output one solution that satisfies the conditions.
To handle large input and output efficiently, you can use faster I/O methods in C++.
In C++, you can use the following lines at the beginning of your main function:
ios::sync_with_stdio(false);
cin.tie(nullptr);
This will speed up I/O operations by disabling the synchronization between C++ and C I/O streams and untie cin from cout, making cin operate independently of cout.
相关
在下列比赛中: