784 - Maze Exploration

#include <stdio.h>
#include <string.h>

char maze[50][100];
void search(int i,int j)
{
	if(maze[i][j]!='*' && maze[i][j]!='_' && maze[i][j]!=' ')
		return;
	maze[i][j]='#';
	search(i-1,j-1);
	search(i-1,j);
	search(i-1,j+1);
	search(i,j-1);
	search(i,j+1);
	search(i+1,j-1);
	search(i+1,j);
	search(i+1,j+1);
}

int main()
{
	int n;
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		memset(maze,'0',sizeof(maze));
		int h=0,w=0;
		while(gets(maze[h]) && maze[h][0]!='_')
		{
			if(strlen(maze[h])>w)
				w=strlen(maze[h]);
			h++;
		}
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
			{
				if(maze[i][j]=='*')
				{
					search(i,j);
				}
			}
			for(int i=0;i<=h;i++)
				printf("%s\n",maze[i]);
	}
	return 0;
}
时间: 2024-11-09 06:19:30

784 - Maze Exploration的相关文章

uva 784 Maze Exploration(DFS遍历图)

uva 784 Maze Exploration A maze(迷宫) of rectangular(矩形的) rooms is represented on a two dimensional(空间的) grid as illustrated(阐明) in figure 1a. Each point of the grid is represented by a character. The points of room walls are marked by the same charact

UVa 784 Maze Exploration

方法:dfs(flood fill) dfs code: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <string> 6 #include <vector> 7 #include <stack> 8 #include <bitset> 9 #include &l

uva 784 Maze Exploration(简单dfs)

这道题看上去很麻烦,什么迷宫啊,门之类的,其实挺简单的,就是让把与 * 连通的都置为 # 包括 * , 直接dfs就可以了,不过我wa了好多次...最后竟然是多读了一个换行,忘了加getchar()了,gets()函数 会把缓冲区里面的换行给读进去的...应该把换行去掉,血的教训啊... 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> int dx[4]={-1,0,0,1}; int dy[4]=

Maze Exploration UVA 784 (简单的深度优先搜索)

说说: 这道题的题意,事先题目给你如下图所示: XXXXXXXXX X         X       X X    *             X X        X        X XXXXXXXXX X        X X        X X        X XXXXX 可以把以上图像想象成一间房子,字符'X'是围墙,你现在所处的位置是'*'所在的地方,要求你将'*'周围的空白,包括'*'本身全部用'#代替.注意不能穿越围墙.其实就是最最基础的深度遍历的问题,只要找到'*'所在的

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA 784-Maze Exploration(dfs)

Maze Exploration A maze of rectangular rooms is represented on a two dimensional grid as illustrated in figure 1a. Each point of the grid is represented by a character. The points of room walls are marked by the same character which can be any printa

UVa 784 迷宫探索

题意:迷宫里有X作为墙,空格为可通过,*标记起点.然后需要你现在来刷墙,刷那些由起点可达的房间的墙,即找由起点可达的连通块.这里题目说墙是除几个字符之外的可打印字符,没有说是X.做题时当成了X,结果AC了~题目说到墙都是3格子宽1格子厚,好像也没什么用~ 思路:输入时找到起点并记下,然后由起点深搜. 注意:从网站拷贝样例数据到txt时,它自动地少了很多空格,导致这个测试数据时不符合题意的.(不容易发现复制粘贴过程中少了很多空格~)这样的话,如果是我代码中dfx中的注释掉的那个 if 语句,程序就

hdu 5094 Maze bfs+状态压缩

Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 642    Accepted Submission(s): 229 Problem Description This story happened on the background of Star Trek. Spock, the deputy captain of St

[LeetCode] The Maze III 迷宫之三

There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up (u), down (d), left (l) or right (r), but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction. T