CodeForces 377 A. Maze

Source: Internet
Author: User


The open space at the end of DFS is changed to a wall ......

A. Mazetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Pavel loves grid mazes. A grid maze isN? ×?MRectangle 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 Wils. he wants to turn exactlyKEmpty cells into Wils so that all the remaining cells still formed a connected area. Help him.

Input

The first line contains three integersN,M,K(1? ≤?N,?M? ≤? 500, 0? ≤?K? S), WhereNAndMAre the maze's height and width, correspondingly,KIs the number of Wils Pavel wants to add and letterSRepresents the number of empty cells in the original maze.

Each of the nextNLines containsMCharacters. 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

PrintNLines containingMCharacters each: the new maze that fits Pavel's requirements. mark the empty cells that you transformed into Wallas "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.

Sample test (s) input
3 4 2#..#..#.#...
Output
#.X#X.#.#...
Input
5 4 5#...#.#..#.....#.#.#
Output
#XXX#X#.X#.....#.#.#

#include 
 
  #include 
  
   #include 
   
    using namespace std;char mp[512][512];bool vis[512][512];int n,m,k;void dfs(int x,int y){    if(x<0||x>=n||y<0||y>=m) return ;    if(mp[x][y]!='.') return ;    if(vis[x][y]) return ;    vis[x][y]=true;    dfs(x+1,y); dfs(x-1,y);    dfs(x,y+1); dfs(x,y-1);    if(k) mp[x][y]='X',k--;}int main(){    scanf("%d%d%d",&n,&m,&k);    for(int i=0;i
    
     



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.