CF377A.Maze

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.

Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

帕维尔喜欢网格迷宫。一个网格迷宫是一个 n×mn \times m 的矩形迷宫,其中每个格子要么是空的,要么是一堵墙。仅当两个格子均为空且有公共边时,才能从其中一个格子移动到另一个格子。

帕维尔画出了一个网格迷宫,其中所有空格子构成一个连通区域,即任意两个空格子之间都存在一条路径。帕维尔不喜欢他的迷宫中墙太少。他希望恰好将 kk 个空格子变为墙,使得剩余的所有空格子仍然构成一个连通区域。请帮助他。

输入格式

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.

Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

第一行包含三个整数 nn、mm、kk(1≤n,m≤5001 \leq n, m \leq 500,0≤k<s0 \leq k < s),其中 nn 和 mm 分别表示迷宫的高度与宽度,kk 表示 Pavel 希望添加的墙壁数量,字母 ss 表示原始迷宫中空单元格的总数。

接下来的 nn 行,每行包含 mm 个字符,用于描述原始迷宫。若某行中的字符为 .,则对应单元格为空;若字符为 #,则该单元格为墙壁。

输出格式

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").

It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

输出 n 行,每行包含 m 个字符:即满足帕维尔(Pavel)要求的新迷宫。将你由空单元格(".")改造而成的墙标记为 "X";其余单元格须保持不变(即仍为 "." 或 "#")。

保证存在解。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3 4 2
    #..#
    ..#.
    #...

    输出#1

    #.X#
    X.#.
    #...
  • 输入#2

    5 4 5
    #...
    #.#.
    .#..
    ...#
    .#.#

    输出#2

    #XXX
    #X#.
    X#..
    ...#
    .#.#

输入解题思路,AI测评打分。不知道怎么写?

首页