#abc257b. B - 1D Pawn
B - 1D Pawn
Score : points
问题描述
有 个正方形,按照从左到右的顺序依次编号为 Square , Square , …, Square 。
同时,存在 个棋子。从左边数起第 个棋子最初被放在 Square 上。
接下来,我们将对这些棋子执行 次操作。第 次操作如下:
- 如果从左边数起第 个棋子已经在它最右侧的正方形上,则不执行任何操作。
- 否则,如果右侧相邻的正方形上没有棋子,则将从左边数起第 个棋子向右移动一个正方形;如果有棋子,则不执行任何操作。
请在所有 次操作结束后,分别输出从左边数起第 个棋子所在的正方形的编号。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are squares, indexed Square , Square , …, Square , arranged in a row from left to right.
Also, there are pieces. The -th piece from the left is initially placed on Square .
Now, we will perform operations against them. The -th operation is as follows:
- If the -th piece from the left is on its rightmost square, do nothing.
- Otherwise, move the -th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the -th piece from the left is after the operations have ended, for each .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print integers in one line, with spaces in between. The -th of them should be the index of the square on which the -th piece from the left is after the operations have ended.
Sample Input 1
5 3 5
1 3 4
3 3 1 1 2
Sample Output 1
2 4 5
At first, the pieces are on Squares , , and . The operations are performed against them as follows:
- The -rd piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -rd piece from the left to Square . Now, the pieces are on Squares , , and .
- The -rd piece from the left is on Square . This is the rightmost square, so do nothing. The pieces are still on Squares , , and .
- The -st piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -st piece from the left to Square . Now, the pieces are on Squares , , and .
- The -st piece from the left is on Square . This is not the rightmost square, but the next square on the right (Square ) contains a piece, so do nothing. The pieces are still on Squares , , and .
- The -nd piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -nd piece from the left to Square ; Now, the pieces are still on Squares , , and .
Thus, after the operations have ended, the pieces are on Squares , , and , so , , and should be printed in this order, with spaces in between.
Sample Input 2
2 2 2
1 2
1 2
Sample Output 2
1 2
Sample Input 3
10 6 9
1 3 5 7 8 9
1 2 3 4 5 6 5 6 2
Sample Output 3
2 5 6 7 9 10
update @ 2024/3/10 10:54:59