A14933 | Playing Around the Table
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ players, numbered from $1$ to $n$ sitting around a round table. The $(i+1)$ -th player sits to the right of the $i$ -th player for $1 \le i < n$ , and the $1$ -st player sits to the right of the $n$ -th player.
There are $n^2$ cards, each of which has an integer between $1$ and $n$ written on it. For each integer from $1$ to $n$ , there are exactly $n$ cards having this number.
Initially, all these cards are distributed among all the players, in such a way that each of them has exactly $n$ cards. In one operation, each player chooses one of his cards and passes it to the player to his right. All these actions are performed simultaneously.
Player $i$ is called solid if all his cards have the integer $i$ written on them. Their objective is to reach a configuration in which everyone is solid. Find a way to do it using at most $(n^2-n)$ operations. You do not need to minimize the number of operations.
There are $n^2$ cards, each of which has an integer between $1$ and $n$ written on it. For each integer from $1$ to $n$ , there are exactly $n$ cards having this number.
Initially, all these cards are distributed among all the players, in such a way that each of them has exactly $n$ cards. In one operation, each player chooses one of his cards and passes it to the player to his right. All these actions are performed simultaneously.
Player $i$ is called solid if all his cards have the integer $i$ written on them. Their objective is to reach a configuration in which everyone is solid. Find a way to do it using at most $(n^2-n)$ operations. You do not need to minimize the number of operations.
输入格式
The first line contains a single integer $n$ ( $2\le n\le 100$ ).
Then $n$ lines follow. The $i$ -th of them contains $n$ integers $c_1, c_2, \ldots, c_n$ ( $1\le c_j\le n$ ) — the initial cards of the $i$ -th player.
It is guaranteed that for each integer $i$ from $1$ to $n$ , there are exactly $n$ cards having the number $i$ .
Then $n$ lines follow. The $i$ -th of them contains $n$ integers $c_1, c_2, \ldots, c_n$ ( $1\le c_j\le n$ ) — the initial cards of the $i$ -th player.
It is guaranteed that for each integer $i$ from $1$ to $n$ , there are exactly $n$ cards having the number $i$ .
输出格式
In the first line print an integer $k$ ( $0\le k\le (n^2-n)$ ) — the numbers of operations you want to make.
Then $k$ lines should follow. In the $i$ -th of them print $n$ integers $d_1, d_2, \ldots, d_n$ ( $1\le d_j\le n$ ) where $d_j$ is the number written on the card which $j$ -th player passes to the player to his right in the $i$ -th operation.
We can show that an answer always exists under the given constraints. If there are multiple answers, print any.
Then $k$ lines should follow. In the $i$ -th of them print $n$ integers $d_1, d_2, \ldots, d_n$ ( $1\le d_j\le n$ ) where $d_j$ is the number written on the card which $j$ -th player passes to the player to his right in the $i$ -th operation.
We can show that an answer always exists under the given constraints. If there are multiple answers, print any.
输入输出样例
输入 #1
2 2 1 1 2
输出 #1
1 2 1
输入 #2
3 1 1 1 2 2 2 3 3 3
输出 #2
6 1 2 3 3 1 2 2 3 1 1 2 3 3 1 2 2 3 1
In the first test case, if the first player passes a card with number $2$ and the second player passes a card with number $1$ , then the first player has two cards with number $1$ and the second player has two cards with number $2$ . Then, after making this operation, both players are solid.
In the second test case, $0$ operations would be enough too. Note that you do not need to minimize the number of operations.
In the second test case, $0$ operations would be enough too. Note that you do not need to minimize the number of operations.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted