UVA 784 Maze Exploration
2016-07-20 19:50
411 查看
UVA-784
题意:给出n个图,每个图以一行_ 结束,其中*是初始位置,X是墙壁,求人可以走到的地方,并用#替换空格,输出整个图。解题思路:找到人物在的位置,dfs开始遍历,到的地方就改成#。
/************************************************************************* > File Name: UVA-784.cpp > Author: Narsh > > Created Time: 2016年07月20日 星期三 13时56分32秒 ************************************************************************/ #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; string s[60]; int t,l; const int c[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; void dfs(int x, int y) { if (s[x][y] != ' ') return ; s[x][y]='#'; for (int i = 0; i < 4; i++) dfs(x+c[i][0],y+c[i][1]); } int main() { scanf("%d\n",&t); while (t--) { l=0; while (true) { l++; getline(cin,s[l]); s[l]=" "+s[l]; if (s[l][1] == '_') break; } for (int i = 1; i <= l; i++) for (int j = 1; j < s[i].length(); j++) if (s[i][j] == '*') { s[i][j]= ' '; dfs(i,j); } for (int i = 1; i <= l; i++){ for (int j = 1; j < s[i].length(); j++) printf("%c",s[i][j]); printf("\n"); } } }
相关文章推荐
- 【听说是线段树】bzoj1012 [JSOI2008]最大数maxnumber
- Android关于Jenkins+Gradle自动化构建时Gradle版本冲突的问题
- 子fragment中加载listview
- hdu5699货物运输
- 高德地图导航简单实例
- sql语句和一些命令
- java基础笔记精简版
- 分数加减法
- UVA-11374(最短路)
- 一个非计算机专业的安卓工程师成长之路
- java之异常
- HDU 4597 Play Game[博弈论 负值最大函数 记忆化搜索]
- html5文件-上传
- 【NOIP2007提高组T3】矩阵取数游戏-动态规划+高精度
- NOIPの模拟_2016_7_20_t2_Graph Coloring
- [283] Move Zeroes
- centos6.3 安装配置redis
- Codeforces Round #363 D Fix a Tree(并查集)
- UVA 657 The die is cast
- (面试)指针与数组的区别