QOJ.ac

QOJ

Limite de temps : 1 s - 2 s Limite de mémoire : 1024 MB Points totaux : 20

#5864. 正方形瓷砖

Statistiques

你正在销售精美的几何图案。每一幅图案都由排列成网格的 $1 \times 1$ 方块组成。例如:

.##..
.####
.####
.##..

蓝色方块用 '#' 字符表示,白色方块用 '.' 字符表示。你不会使用其他颜色。

然而,并不是每个人都喜欢蓝色,有些顾客希望你将图案中所有的蓝色方块替换为红色方块。不幸的是,红色方块只有较大的 $2 \times 2$ 尺寸,这使得任务变得棘手。

你可以用一块红色方块覆盖任意 $2 \times 2$ 的蓝色方块区域,并重复此过程直到完成。红色方块不能重叠,不能覆盖白色方块,也不能超出图案边界。例如,你可以按照以下方式为之前的图案添加红色方块:

./\..
.\//\
./\\/
.\/..

这里每块红色方块由左上角和右下角的 '/' 字符,以及另外两个角的 '\' 字符表示。

给定一幅蓝白相间的图案,你能否通过这种方式将其转换为红白相间的图案?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。

每个测试用例的第一行包含 $R$ 和 $C$,分别表示图案的行数和列数。接下来的 $R$ 行,每行包含恰好 $C$ 个字符,描述了图案。如上所述,'#' 字符代表蓝色方块,'.' 字符代表白色方块。

输出格式

对于每个测试用例,首先输出一行 "Case #x:",其中 $x$ 是测试用例编号(从 1 开始)。

如果能够用互不重叠的红色方块覆盖所有蓝色方块,则输出 $R$ 行,每行包含 $C$ 个字符,描述转换后的红白图案。如上所述,红色方块应由 '/' 和 '\' 字符表示,而白色方块由 '.' 字符表示。如果存在多种解,输出其中任意一种即可。

如果任务无法完成,则输出一行 "Impossible"。

数据范围

内存限制:1GB。

小数据集(测试集 1 - 可见;10 分)

$1 \le T \le 20$。 $1 \le R \le 6$。 $1 \le C \le 6$。 时间限制:1 秒。

大数据集(测试集 2 - 隐藏;10 分)

$1 \le T \le 50$。 $1 \le R \le 50$。 $1 \le C \le 50$。 时间限制:2 秒。

样例

样例输入 1

3
2 3
###
###
1 1
.
4 5
.##..
.####
.####
.##..

样例输出 1

Case #1:
Impossible
Case #2:
.
Case #3:
./\..
.\//\
./\\/
.\/..

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.