QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 256 MB مجموع النقاط: 100

#12766. 知识产权

الإحصائيات

Erast Kopi 是一位著名的数独谜题设计者。他的谜题集大获成功,但也引来了许多模仿和抄袭。在发送律师函之前,他决定收集更多的证据。

数独谜题是一个 $9 \times 9$ 的表格,被划分为 $3 \times 3$ 个 $3 \times 3$ 的子表。每个单元格可以包含 1 到 9 之间的数字。任务是填入空缺的单元格,使得每一行、每一列以及 9 个 $3 \times 3$ 的子表中都恰好包含 1 到 9 中的每个数字各一次。

Kopi 有一个数独谜题数据库,他想检查其中是否包含相似的谜题。如果可以通过以下一系列操作将谜题 $P$ 转换为谜题 $Q$,则称谜题 $P$ 与谜题 $Q$ 相似:

  • 选择两个数字 $x$ 和 $y$,将所有 $x$ 替换为 $y$,并将所有 $y$ 替换为 $x$;
  • 交换两个行三元组:$(1, 2, 3), (4, 5, 6), (7, 8, 9)$;
  • 交换同一个行三元组中的两行;
  • 交换两个列三元组:$(1, 2, 3), (4, 5, 6), (7, 8, 9)$;
  • 交换同一个列三元组中的两列;
  • 沿左上—右下轴翻转。执行此操作后,列变为行,行变为列。

帮助 Kopi 在他的数据库中找到相似的谜题。

输入格式

输入的第一行包含一个整数 $n$ —— 数据库中谜题的数量 ($1 \le n \le 20$)。 输入的其余部分包含 $n$ 个谜题的描述:$P_1, P_2, \dots, P_n$。每个谜题由九行组成,每行包含九个字符。每个字符要么是 1 到 9 之间的数字,要么是表示空单元格的点(‘.’)。连续的谜题之间由空行分隔。 输入文件中没有空格。 不保证谜题一定有解。

输出格式

检查谜题 $P_1$ 是否与谜题 $P_2, P_3, \dots, P_n$ 相似(按此顺序),然后检查谜题 $P_2$ 是否与谜题 $P_3, P_4, \dots, P_n$ 相似(按此顺序),依此类推。

如果谜题 $P_i$ 与谜题 $P_j$ ($1 \le i < j \le n$) 相似,则输出 “Yes”,否则输出 “No”。 如果答案为肯定,下一行应包含一个整数 $q_{ij}$ —— 将谜题 $P_i$ 转换为谜题 $P_j$ 所需的操作次数。操作次数不需要是最小的,但不得超过 1000。在接下来的 $q_{ij}$ 行中,每行写出一个转换 $P_i$ 到 $P_j$ 的操作。

操作编码如下: “D $x$ $y$”:交换数字 $x$ 和 $y$; “R $a$ $b$”:交换行三元组 $(3a - 2, 3a - 1, 3a)$ 和 $(3b - 2, 3b - 1, 3b)$; “r $a$ $b$”:交换行 $a$ 和 $b$,行必须属于同一个行三元组; “C $a$ $b$”:交换列三元组 $(3a - 2, 3a - 1, 3a)$ 和 $(3b - 2, 3b - 1, 3b)$; “c $a$ $b$”:交换列 $a$ 和 $b$,列必须属于同一个列三元组; “F”:沿左上—右下轴翻转。

列从左到右编号,行从上到下编号,均按照输入文件中的顺序,从 1 开始。

样例

输入 1

4
.....1...
1........
.2.....8.
.........
8....9...
.........
....7....
...2...1.
2...4....
....2....
...7.4...
8.......9
.8...2..1
..2......
.........
.........
..1.8....
.........
1........
.........
.........
.........
.........
.........
.........
.........
.........
.....1...
1........
.2.....8.
.........
8....9...
.........
....7....
...2...1.
2...4....

输出 1

Yes
7
C 1 2
D 5 3
F
r 7 9
c 6 5
C 2 3
D 1 8
No
Yes
0
No
Yes
8
R 1 2
C 2 3
c 4 5
F
r 5 6
c 7 9
D 1 8
D 3 5
No

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.