UVa784 Maze Exploration
// 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符#
注意迷宫边界不规则,要用strlen判断。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 100 + 5;
char maze[maxn][maxn]; int dr[]={0, 0, -1, 1};
int dc[]={1, -1, 0, 0}; int R; void dfs(int r, int c)
{
if(r<0 || r>=R || c<0 || c >=strlen(maze[r])) return;
if(maze[r][c] == 'X' || maze[r][c] == '#') return;
maze[r][c]='#';
for(int i=0;i<4;i++)
{
int nr=r+dr[i];
int nc=c+dc[i];
dfs(nr, nc);
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("./uva784.in", "r", stdin);
#endif
int T;
scanf("%d", &T); gets(maze[0]);
while(T--) {
R=0;
while(1) {
gets(maze[R]);
if(maze[R][0]=='_')
break;
R++;
}
int j=0;
while(j<R)
{
char *p;
if((p=strchr(maze[j], '*'))!=0)
{
int r, c;
c=p-maze[j];
r=j;
dfs(r, c);
}
j++;
} j=0;
while(j<=R)
printf("%s\n", maze[j++]); } return 0;
}
UVa784 Maze Exploration的更多相关文章
- [UVA] 784 - Maze Exploration
Maze Exploration A maze of rectangular rooms is represented on a two dimensional grid as illustra ...
- uva 784 Maze Exploration 染色 搜索水题 DFS
染色问题,其实就是看看图上某一点能扩散多少. 用DFS解决,因为BFS不是很熟 =-=...以后要多练. 提交后32ms,优化了一下,在递归前进行判定,优化到22ms,不是优化的很好... 代码: # ...
- 784 - Maze Exploration
#include <stdio.h> #include <string.h> char maze[50][100]; void search(int i,int j) { if ...
- uva 784 Maze Exploration(简单dfs)
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Undirected Graphs
无向图 Introduction 图是由边连接的点的集合,有着广泛的应用空间. 一些图的术语,点,边,路径,环(圈),连通分量(子图). 简单路径不重复经过点,简单环不含有重复点和边,简单图不含自环和 ...
- Backtracking algorithm: rat in maze
Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- (期望)A Dangerous Maze(Light OJ 1027)
http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...
随机推荐
- UVA 1659 Help Little Laura 帮助小劳拉 (最小费用流,最小循环流)
(同时也是HDU 2982,UVA的数据多) 题意:平面上有m条有向线段连接了n个点.你从某个点出发顺着有向线段行走,给走过的每条线段涂一种不同的颜色,最后回到起点.你可以多次行走,给多个回路涂色(要 ...
- AJAX在GBK编码页面中传中文参数乱码的问题
---恢复内容开始--- 页面编码是GBK的情况下传递中文有乱码,解决方法如下: 在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传 ...
- LeetCode: Single Number I && II
I title: Given an array of integers, every element appears twice except for one. Find that single on ...
- 开发ffmpeg/live555常见问题错误及解决方法
#include <iostream>using namespace std;extern "C" {#include <libavcodec/avcodec.h ...
- Swift compile slow 编译慢问题
http://stackoverflow.com/questions/29707622/bizarre-swift-compiler-error-expression-too-complex-on-a ...
- iE6、7、8、9、10、11兼容的Cookie
<%@ Master Language="C#" Debug="true" AutoEventWireup="true" Inheri ...
- Dev gridControl 按回车增加一行
将NewItemRowPosition属性设置为Top或Bottom, 在这样的新行中输入数据后,会自动添加到绑定的数据源中的, 如果你希望在按回车时焦点跳至下一列, 只需要设置GridView的Op ...
- 六种排序的C++实现
class SortNum { public: SortNum(); virtual ~SortNum(); void exchange(int& b,int& c);//交换数据 v ...
- <转>Python运行的17个时新手常见错误小结
1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 “SyntaxError :invalid syntax”) 该错误将发生在 ...
- Windows下Qt开发环境:OpenGL导入3DMax模型(.3DS)
参考:http://blog.csdn.net/cq361106306/article/details/41876541 效果: 源代码: 解释: CLoad3DS.h为加载3DMax模型的头文件,C ...