309228: CF1646F. Playing Around the Table

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Playing Around the Table

题意翻译

## 题意 有 $n$ 个玩家,从 $1$ 到 $n$ 编号,按顺序形成一个环 $i$ 的右边是 $i + 1$,特别地,$n$ 的右边是 $1$ 。 现在有 $n^2$ 张牌,每张上有一个整数,范围在 $[1, n]$ ,其中值为 $i$ 的牌有 $n$ 张。 每一次操作,令每个玩家选择一张牌给自己的下家。所有这些操作都是同时执行的。 玩家 $i$ 的目标是得到 $n$ 张值为 $i$ 的牌。请找出一种方案:在不超过 $(n ^ 2 - n)$ 次操作使每个玩家达成目标。 你不需要使操作数最小化。 Translated by JDS070115. ### 输入格式: 第一行一个整数 $n$ 。 接下来 $n$ 行,第 $i$ 行有 $n$ 个整数 $c_1, c_2, \dots , c_n$ 表示玩家 $i$ 初始有的牌。 保证数据合法。 ### 输出格式: 第一行一个整数 $k$ 表示你的操作数。 接下来 $k$ 行,第 $i$ 行有 $n$ 个整数 $d_1, d_2, \dots , d_n$ ,其中 $d_j$ 表示第 $i$ 次操作时,玩家 $j$ 给了下家值为 $d_j$ 的牌。 我们可以证明,在给定的限制下,答案总是存在的。如果有多个答案,请输出任意一种答案。 ### 数据范围: $2 \leq n \leq 100$

题目描述

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.

输入输出格式

输入格式


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 $ .

输出格式


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.

输入输出样例

输入样例 #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.

Input

题意翻译

## 题意 有 $n$ 个玩家,从 $1$ 到 $n$ 编号,按顺序形成一个环 $i$ 的右边是 $i + 1$,特别地,$n$ 的右边是 $1$ 。 现在有 $n^2$ 张牌,每张上有一个整数,范围在 $[1, n]$ ,其中值为 $i$ 的牌有 $n$ 张。 每一次操作,令每个玩家选择一张牌给自己的下家。所有这些操作都是同时执行的。 玩家 $i$ 的目标是得到 $n$ 张值为 $i$ 的牌。请找出一种方案:在不超过 $(n ^ 2 - n)$ 次操作使每个玩家达成目标。 你不需要使操作数最小化。 Translated by JDS070115. ### 输入格式: 第一行一个整数 $n$ 。 接下来 $n$ 行,第 $i$ 行有 $n$ 个整数 $c_1, c_2, \dots , c_n$ 表示玩家 $i$ 初始有的牌。 保证数据合法。 ### 输出格式: 第一行一个整数 $k$ 表示你的操作数。 接下来 $k$ 行,第 $i$ 行有 $n$ 个整数 $d_1, d_2, \dots , d_n$ ,其中 $d_j$ 表示第 $i$ 次操作时,玩家 $j$ 给了下家值为 $d_j$ 的牌。 我们可以证明,在给定的限制下,答案总是存在的。如果有多个答案,请输出任意一种答案。 ### 数据范围: $2 \leq n \leq 100$

加入题单

算法标签: