QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#250. 地图拼图

Statistics

你需要编写一个求解器来完成一幅地图拼图。每个拼图块都是正方形,其边缘对应地图上的标记。共有六种不同的边缘类型:道路 (R)、城市 (C)、农场 (F)、河流 (S)、湖泊 (L) 和巨石 (B)。拼图块将放入一个行列网格中,相邻的边缘必须匹配。网格最外层的边缘不与任何其他拼图块的边缘相邻,即没有环绕效果。

输入格式

输入的第一行包含测试用例的数量 $T$ ($1 \leq T \leq 50$)。

每个测试用例的第一行包含网格的行数 $R$ 和列数 $C$ ($1 \leq R, C \leq 50$)。

接下来的 $R \times C$ 行,每行包含一个拼图块,用 4 个字符表示,分别代表北、东、南、西四个边。

每个拼图的第一个输入块为起始块。它是固定的,即不能旋转,并将被放置在网格的第一行第一列。后续的拼图块可以放置在拼图网格中的任何其他位置,并可以根据需要进行旋转以找到合适的匹配。

输出格式

输出由完成的拼图组成,共 $R \times 5$ 行,每行 $C \times 5$ 个字符。每个 $5 \times 5$ 的方块代表一个拼图块,格式如下:

+---+
| F |
|L R|
| B |
+---+

保证每个拼图都有唯一的解。

测试用例之间将由一个空行分隔。

样例

样例输入 1

2
2 3
FRCR
CLLB
FFSB
FLRB
LRLC
FRSF
2 2
CCBC
CSRB
SLFF
LCRR

样例输出 1

+---++---++---+
| F || B || R |
|R R||R F||F S|
| C || L || F |
+---++---++---+
+---++---++---+
| C || L || F |
|L L||L B||B F|
| R || C || S |
+---++---++---+

+---++---+
| C || R |
|C C||C R|
| B || L |
+---++---+
+---++---+
| B || L |
|B S||S F|
| R || F |
+---++---+

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.