QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 32 MB Total points: 70

#17074. CROSS

Statistics

在数独游戏中,目标是将 $1$ 到 $9$(含)之间的整数填入一个 $9 \times 9$ 的网格中,使得每一行、每一列以及九个 $3 \times 3$ 的宫(box)中都包含所有这九个数字。初始盘面会部分填入数字,以便能够通过逻辑推导确定其他空格的值。数独谜题的难度各不相同,解决最难的谜题需要复杂的分析方法。然而,在本题中,你只需要实现其中最简单的一种方法:排除法(cross-hatching)

在排除法中,我们选择 $1$ 到 $9$ 中的一个数字,对于它在网格中每一次出现,都交叉划掉其所在的行、列以及 $3 \times 3$ 的宫。然后,寻找是否存在某个 $3 \times 3$ 的宫,其中该数字只有唯一一个可能填入的位置,并将其填入该位置。

下方第一幅图展示了一个非常稀疏的数独网格。然而,即使在这个网格中,也可以通过排除法推导出左上角的单元格中的数字是 $4$,如第二幅图所示。

你将获得一个部分填写的网格。你的任务是针对不同的数字重复应用排除法,直到无法再对任何数字做出进一步的推导为止。

初始网格中的数字布局可能是无效的。也有可能在某个 $3 \times 3$ 的宫中,某个数字没有任何可填入的单元格。在这两种情况下,你都需要报告错误。

输入格式

输入包含 $9$ 行,每行恰好包含 $9$ 个字符。每个字符要么是 $1$ 到 $9$ 之间的数字,要么是表示空格的英文句点(.)。

输出格式

如果输入有效且在求解过程中没有出现矛盾,你应该以与输入相同的格式输出网格,其中填入可以通过排除法推导出的单元格的值。否则,输出 ERROR

样例

输入样例 1

..9......
.....4...
.......4.
.........
.4.......
.........
.........
.........
.........

输出样例 1

4.9......
.....4...
.......4.
.........
.4.......
.........
.........
.........
.........

输入样例 2

...1...6.
18...9...
..7.642..
2.9..6.5.
.43...72.
.6.3..9.1
..265.1..
...2...97
.5...3...

输出样例 2

524137869
186529473
397864215
219476358
843915726
765382941
972658134
638241597
451793682

输入样例 3

1........
..1......
.......1.
.........
.........
.........
.........
.........
.........

输出样例 3

ERROR

输入样例 4

........2
....1....
1........
......1..
.........
.........
.........
.......1.
.........

输出样例 4

ERROR

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.