#abc250c. C - Adjacent Swaps
C - Adjacent Swaps
Score : points
问题描述
设有 个球从左到右排成一行。最初,从左边数第 个球()上写着整数 。
Takahashi 执行了 次操作。第 次操作()如下:
- 将写有整数 的球与它右边的下一个球交换。如果原本写有整数 的球是最右边的球,则与其左边的下一个球交换。
令 表示执行完操作后,从左边数第 个球()上所写的整数。求出 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
balls are lined up in a row from left to right. Initially, the -th () ball from the left has an integer written on it.
Takahashi has performed operations. The -th () operation was as follows.
- Swap the ball with the integer written on it with the next ball to the right. If the ball with the integer written on it was originally the rightmost ball, swap it with the next ball to the left instead.
Let be the integer written on the -th () ball after the operations. Find .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print , with spaces in between.
Sample Input 1
5 5
1
2
3
4
5
Sample Output 1
1 2 3 5 4
The operations are performed as follows.
- Swap the ball with written on it with the next ball to the right. Now, the balls have integers written on them, from left to right.
- Swap the ball with written on it with the next ball to the right. Now, the balls have integers written on them, from left to right.
- Swap the ball with written on it with the next ball to the right. Now, the balls have integers written on them, from left to right.
- Swap the ball with written on it with the next ball to the right. Now, the balls have integers written on them, from left to right.
- Swap the ball with written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers written on them, from left to right.
Sample Input 2
7 7
7
7
7
7
7
7
7
Sample Output 2
1 2 3 4 5 7 6
Sample Input 3
10 6
1
5
2
9
6
6
Sample Output 3
1 2 3 4 5 7 6 8 10 9
update @ 2024/3/10 10:41:03