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.

Input

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.

Output

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.

Example

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

Output
#.X#
X.#.
#...

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

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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;char m[505][505];
int l,r,k;void dfs(int x,int y)
{if(x<0||y<0||x>=l||y>=r){return ;}if(m[x][y]=='X'){if(k==0)return ;else{k++;m[x][y]='.';dfs(x-1,y);dfs(x,y-1);dfs(x,y+1);dfs(x+1,y);}}
}int main()
{int i,j,x,y;while(~scanf("%d %d %d\n",&l,&r,&k)){for(i=0;i<l;i++){for(j=0;j<r;j++){scanf("%c",&m[i][j]);if(m[i][j]=='.'){k--;m[i][j]='X';x=i;y=j;}}getchar();}dfs(x,y);for(i=0;i<l;i++)printf("%s\n",m[i]);}return 0;
}

Maze CodeForces - 377A相关推荐

  1. CODEFORCES 377A

    http://codeforces.com/problemset/problem/377/A D - Maze CodeForces - 377A http://blog.csdn.net/keshu ...

  2. Solve The Maze CodeForces - 1365D(贪心+dfs)

    Vivek has encountered a problem. He has a maze that can be represented as an n×m grid. Each of the g ...

  3. D. Solve The Maze Codeforces Round #648 (Div. 2)

    D. Solve The Maze Vivek has encountered a problem. He has a maze that can be represented as an n×m g ...

  4. HZNU Training 4 for Zhejiang Provincial Collegiate Programming Contest 2019

    今日这场比赛我们准备的题比较全面,二分+数论+最短路+计算几何+dp+思维+签到题等.有较难的防AK题,也有简单的签到题.为大家准备了一份题解和AC代码. A - Meeting with Alien ...

  5. codeforces 378C MAZE

    D - Maze Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  6. 【Codeforces - 378C】Maze(dfs,思维)

    题干: Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, ...

  7. CodeForces 377 A. Maze

    DFS找末端的空地变成墙...... A. Maze time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  8. CodeForces - 1293C NEKO's Maze Game(思维,水题)

    题目链接:点击查看 题目大意:给出一个2*n大小的矩阵,现在有m次操作,每次操作将某一个方格的状态置反,这里的每个方块都有两种状态,一种状态是可通行状态,另一种是不可通行状态,初始时所有方块都是可通行 ...

  9. Codeforces Round #222 (Div. 2): C. Maze(BFS)

    题意: 给你一个n*m的迷宫,'.'是路,'#'是墙,输入保证所有的'.'构成一个联通块,要求为这个迷宫再添加k面墙,使得剩下所有的'.'仍然构成一个联通块 思路:反过来处理,先将所有的'.'全部变成 ...

  10. codeforces D. Solve The Maze

    题目 题意: 你有一个地图,总共有 4 4 4种符号,'.','#',' G G G',' B B B',分别代表着路,墙,好人,坏人,现在你可以将路变成墙,问最后是否有一种方案使得坏人走不到 n , ...

最新文章

  1. Android Studio 3.5 Canary 12 发布
  2. CPU制作流程大揭密
  3. C++_引用变量探究
  4. 线性表C语言locate和ETget,线性表(数据结构重难点讲解)
  5. Flutter中Row中的子控件左右两端对齐
  6. 工作流与Petri net的关系
  7. BAPI_GOODSMVT_CREATE 移动类型311 CODE = '04' 代码
  8. node.js util全局变量和事件驱动events
  9. Unity使用自定义资源(.asset)配置数据
  10. jmeter学习总结
  11. ASP.NET MVC3 系列教程 - URL友好化的重型武器[路由]
  12. 【Multisim仿真+报告+演示视频】数电课设五人表决器Multisim仿真设计【全套资料】资源编号:YM5-V1.0.1-五人表决器
  13. 泰坦尼克号生存率预测
  14. 佛系前端面试题记录--第二周
  15. 前端标注工具标你妹啊与马克鳗小对比
  16. JAVA野人_修道野人 用谓词表示法表示修道士和野人的问题 在河的左岸有三个修道士 联合开发网 - pudn.com...
  17. STM32F767+TB6600+57步进电机
  18. 业余时间决定你的人生
  19. 《货币商人》读后感作文选登3800字
  20. 国外PPT简历模板,免费领取

热门文章

  1. R 聚类热图-数据的标准化
  2. Google一些关键词的运用
  3. html中三角函数表示什么,三角函数a怎么求
  4. 深入mysql语言_深入简出mysql--第一部分
  5. 在自己本地原有的镜像基础上用dockerfile加一下库进去
  6. ios设备的弹窗页面,光标错位,光标乱跳
  7. ISCW实验11:使用SDM配置Site-to-Site IPSec ×××
  8. ReadyBoost 的应用教程
  9. java gps809_车载GPS对接809协议的数据对接
  10. 大众与以色列前情报头子组建网络安全公司