#P5918. [FJOI2015] 金币换位问题
[FJOI2015] 金币换位问题
Problem Description
Given an integer , the initial sequence looks like this:
$$\underbrace{\tt 111\cdots11}_{n \text{ ones}}\underbrace{\tt 000\cdots00}_{n \text{ zeros}}\verb!__!$$Now you need to use the minimum number of swaps to make the final sequence become:
$$\underbrace{\tt 101010\cdots 1010}_{2\times n \text{ digits with alternating } 0 \text{ and } 1}\verb!__!$$A swap means moving two adjacent non-blank digits together onto the two blanks.
For example, the following is a valid solution when :
- Initial state: .
- Step : .
- Step : .
- Step : .
- Step : .
- Step : .
It can be proven that the minimum number of operations is .
Input Format
The input contains one line with an integer .
Output Format
Output the minimum number of moves in the first line.
In the next line, output a move plan. You only need to output the index of the left one of the two moved non-blank cells. See the sample for details.
4
5
1 4 8 6 9
Hint
For of the testdata, .
Translated by ChatGPT 5