CF1495C.Garden of the Sun
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are many sunflowers in the Garden of the Sun.
Garden of the Sun is a rectangular table with n rows and m columns, where the cells of the table are farmlands. All of the cells grow a sunflower on it. Unfortunately, one night, the lightning stroke some (possibly zero) cells, and sunflowers on those cells were burned into ashes. In other words, those cells struck by the lightning became empty. Magically, any two empty cells have no common points (neither edges nor corners).
Now the owner wants to remove some (possibly zero) sunflowers to reach the following two goals:
- When you are on an empty cell, you can walk to any other empty cell. In other words, those empty cells are connected.
- There is exactly one simple path between any two empty cells. In other words, there is no cycle among the empty cells.
You can walk from an empty cell to another if they share a common edge.
Could you please give the owner a solution that meets all her requirements?
Note that you are not allowed to plant sunflowers. You don't need to minimize the number of sunflowers you remove. It can be shown that the answer always exists.
太阳花园里有许多向日葵。
太阳花园是一个 n 行 m 列的矩形表格,表格中的每个格子是一块农田,每块农田上都生长着一株向日葵。不幸的是,某天夜里,闪电击中了其中一些(可能为零)格子,这些格子上的向日葵被烧成了灰烬。换言之,被闪电击中的格子变为空地。神奇的是,任意两个空地格子之间没有公共点(既不共享边,也不共享角)。
现在,园主希望移除一些(可能为零)向日葵,以满足以下两个目标:
- 当你位于某个空地格子上时,你可以走到任意其他空地格子。换言之,所有空地格子是连通的。
- 任意两个空地格子之间恰好存在一条简单路径。换言之,空地格子之间不存在环。
当两个空地格子共享一条公共边时,你才可以从其中一个走到另一个。
你能为园主提供一个满足所有要求的方案吗?
注意:你不允许种植向日葵。你无需最小化所移除的向日葵数量。可以证明,这样的解总是存在的。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line contains two integers n, m (1≤n,m≤500) — the number of rows and columns.
Each of the next n lines contains m characters. Each character is either 'X' or '.', representing an empty cell and a cell that grows a sunflower, respectively.
It is guaranteed that the sum of n⋅m for all test cases does not exceed 250000.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
第一行包含两个整数 n 和 m(1≤n,m≤500),分别表示行数和列数。
接下来的 n 行,每行包含 m 个字符。每个字符为 'X' 或 '.',分别表示空单元格和种植向日葵的单元格。
保证所有测试用例中 n⋅m 的总和不超过 250000。
输出格式
For each test case, print n lines. Each should contain m characters, representing one row of the table. Each character should be either 'X' or '.', representing an empty cell and a cell with a sunflower, respectively.
If there are multiple answers, you can print any. It can be shown that the answer always exists.
对于每个测试用例,输出 n 行。每行应包含 m 个字符,表示表格的一行。每个字符应为 'X' 或 '.',分别表示空单元格和种有向日葵的单元格。
若存在多个合法答案,输出任意一个即可。可以证明答案一定存在。
输入输出样例
输入#1
5 3 3 X.X ... X.X 4 4 .... .X.X .... .X.X 5 5 .X... ....X .X... ..... X.X.X 1 10 ....X.X.X. 2 2 .. ..
输出#1
XXX ..X XXX XXXX .X.X .X.. .XXX .X... .XXXX .X... .X... XXXXX XXXXXXXXXX .. ..
说明/提示
Let's use (x,y) to describe the cell on x-th row and y-th column.
In the following pictures white, yellow, and blue cells stand for the cells that grow a sunflower, the cells lightning stroke, and the cells sunflower on which are removed, respectively.

In the first test case, one possible solution is to remove sunflowers on (1,2), (2,3) and (3,2).

Another acceptable solution is to remove sunflowers on (1,2), (2,2) and (3,2).

This output is considered wrong because there are 2 simple paths between any pair of cells (there is a cycle). For example, there are 2 simple paths between (1,1) and (3,3).
-
(1,1)→(1,2)→(1,3)→(2,3)→(3,3)
-
(1,1)→(2,1)→(3,1)→(3,2)→(3,3)

This output is considered wrong because you can't walk from (1,1) to (3,3).
我们使用 (x,y) 表示第 x 行、第 y 列的格子。
在以下图示中,白色、黄色和蓝色格子分别表示种植向日葵的格子、遭受雷击的格子以及被移除向日葵的格子。

在第一个测试用例中,一种可行的方案是移除位于 (1,2)、(2,3) 和 (3,2) 的向日葵。

另一种可接受的方案是移除位于 (1,2)、(2,2) 和 (3,2) 的向日葵。

该输出被视为错误,因为任意两个格子之间存在两条简单路径(即图中存在环)。例如,在 (1,1) 与 (3,3) 之间存在两条简单路径:
-
(1,1)→(1,2)→(1,3)→(2,3)→(3,3)
-
(1,1)→(2,1)→(3,1)→(3,2)→(3,3)

该输出被视为错误,因为你无法从 (1,1) 走到 (3,3)。
输入解题思路,AI测评打分。不知道怎么写?