QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#10345. Amanda the Amoeba

Statistics

变形虫 Amanda 生活在一个矩形的方格网格中。她的身体占据了其中的一些像素。其他像素可能是空闲的,也可能是被阻挡的。Amanda 使用所谓的“变形虫运动”在网格中移动。在每一次这样的移动中,她的身体首先收缩一个像素(从身体中移除一个像素,使其变为空闲),然后在一个不同的位置生长(将一个之前空闲的像素添加到身体中)。

为了防止结构损坏,Amanda 的身体始终占据一个连通的像素区域,这意味着身体中的任意两个像素都可以通过一系列相邻的像素连接起来,且路径始终在身体内部。如果两个像素共享一条公共边,则认为它们是相邻的(每个像素最多有 4 个邻居)。身体在移动过程中始终保持连通,包括移除一个像素之后、添加另一个像素之前的瞬间。

你的任务是帮助 Amanda 找到她的移动路径。给定她的初始位置和期望的最终位置,请给出一系列从前者到达后者的有效移动步骤。

样例 1 说明:实心形状为初始位置,虚线区域为最终位置。

输入格式

第一行包含两个整数 $r$ 和 $c$ ($1 \le r, c \le 50$),表示矩形网格的像素大小。

接下来的 $r$ 行,每行包含 $c$ 个字符,描述 Amanda 的初始位置。每个字符要么是表示空闲像素的 .,要么是表示 Amanda 身体的 *,要么是表示永远无法被占据的阻挡像素 X

接下来是一个空行。

接下来的 $r$ 行以与初始位置相同的格式描述期望的最终位置。

保证: Amanda 身体所占的像素数量在两个位置中相同,且至少为 2。 Amanda 的身体在初始位置是连通的。 Amanda 的身体在最终位置是连通的。 阻挡像素在初始位置和最终位置描述之间不会改变,它们的位置完全相同。

输出格式

如果 Amanda 可以从初始位置移动到最终位置,请输出 YES。否则,输出 NO。

如果可能,在下一行输出一个整数 $m$ ($0 \le m \le 10\,000$),表示执行的移动次数。

接下来的 $m$ 行,每行必须包含四个整数坐标:$i_1, j_1, i_2, j_2$ ($1 \le i_1, i_2 \le r$, $1 \le j_1, j_2 \le c$)。这四个坐标指定了一次移动,意味着位于第 $i_1$ 行第 $j_1$ 列的像素首先从身体中移除。然后,$(i_2, j_2)$ 必须指定一个不同的位置,在该位置添加一个像素。

该序列应仅包含有效的移动,并且在最后一次移动后,Amanda 的身体应占据期望的最终位置。

如果有多种解,输出其中任意一个即可。

根据本题的假设,可以证明如果 Amanda 可以从初始位置移动到期望的最终位置,那么最多可以通过 $10\,000$ 次移动完成。

样例

输入 1

5 8
.******.
**.X**..
*******.
**.X**..
.******.

.******.
...X****
.*******
...X****
.******.

输出 1

YES
5
3 1 3 8
2 1 2 8
4 1 4 8
2 2 4 7
4 2 2 7

说明 1

Amanda 执行了 5 次移动以到达最终位置,如下图所示。

输入 2

2 5
*.X..
**X..

..X**
..X*.

输出 2

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.