#abc213c. C - Reorder Cards
C - Reorder Cards
Score : points
问题描述
我们有张卡片排列成一个矩阵,包含行和列。
对于每个,在从上到下的第行以及从左到右的第列的卡片上写有一个数字。其余张卡片上则没有写任何数字。
我们将尽可能多地对这些卡片重复以下两种操作。
- 如果存在一行没有编号的卡片,则移除该行的所有卡片,并通过将剩余卡片向上移动来填补空缺。
- 如果存在一列没有编号的卡片,则移除该列的所有卡片,并通过将剩余卡片向左移动来填补空缺。
找出上述过程结束后每张编号卡片的位置。可以证明,这些位置是唯一确定的,与操作执行的顺序无关。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have cards arranged in a matrix with rows and columns.
For each , the card at the -th row from the top and -th column from the left has a number written on it. The other cards have nothing written on them.
We will repeat the following two kinds of operations on these cards as long as we can.
- If there is a row without a numbered card, remove all the cards in that row and fill the gap by shifting the remaining cards upward.
- If there is a column without a numbered card, remove all the cards in that column and fill the gap by shifting the remaining cards to the left.
Find the position of each numbered card after the end of the process above. It can be proved that these positions are uniquely determined without depending on the order in which the operations are done.
Constraints
- All pairs are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines.
If, after the end of the process, the card with the number is at the -th row from the top and -th column from the left, the -th line should contain and in this order with a space between them.
Sample Input 1
4 5 2
3 2
2 5
Sample Output 1
2 1
1 2
Let *
represent a card with nothing written on it. The initial arrangement of cards is:
*****
****2
*1***
*****
After the end of the process, they will be arranged as follows:
*2
1*
Here, the card with is at the -nd row from the top and -st column from the left, and the card with is at the -st row from the top and -nd column from the left.
Sample Input 2
1000000000 1000000000 10
1 1
10 10
100 100
1000 1000
10000 10000
100000 100000
1000000 1000000
10000000 10000000
100000000 100000000
1000000000 1000000000
Sample Output 2
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
update @ 2024/3/10 09:29:23