Maze Exploration UVA
来源:互联网 发布:淘宝客服如何设置分流 编辑:程序博客网 时间:2024/06/05 14:43
题目链接:点击打开链接
题意: 把与 * 相连的空格改成 # ,X为墙,即无法通过;
题解:
简单DFS,没有什么难度,就是输入有点坑,至今都没有弄出来咋错的;
AC代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char mmap[100][100];int n;int dx[4]= {0,-1,0,1};int dy[4]= {1,0,-1,0};void dfs(int s,int e){ mmap[s][e]='#'; for(int i=0;i<4;i++) { int x=s+dx[i]; int y=e+dy[i]; if(mmap[x][y]==' ') { dfs(x,y); } }}int main(){ int t; scanf("%d%*c",&t); while(t--) { int i=0,j,k; memset(mmap,0,sizeof(mmap)); while(gets(mmap[i])!=NULL) { if(mmap[i][0]=='_')break; i++; } n=i; for(i=0; i<n; i++) { for(j=0; mmap[i][j]!='\0'; j++) { if(mmap[i][j]=='*') dfs(i,j); } } for(i=0; i<=n; i++) printf("%s\n",mmap[i]); } return 0;}
我的错代码(坑):
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char s[100][100];int dxy[4][2]={0,-1,-1,0,1,0,0,1};void dfs(int x,int y){ s[x][y]='#'; for(int i=0;i<4;i++){ int dx=x+dxy[i][0]; int dy=y+dxy[i][1]; if(s[dx][dy]==' '){ dfs(dx,dy); } }}int main(){ int T; scanf("%d",&T); getchar(); while(T--){ int k=0; memset(s,0,sizeof(s)); while(gets(s[k])){ k++; if(s[k-1][0]=='_') break; } for(int i=0;i<k;i++){ for(int j=0;s[i][j]!='\0';j++){ if(s[i][j]=='*'){ dfs(i,j); } } } for(int i=0;i<k;i++){ printf("%s\n",s[i]); } } return 0;}
阅读全文
0 0
- UVa 784 Maze Exploration
- uva 784 - Maze Exploration
- uva 784 - Maze Exploration
- uva 784 - Maze Exploration
- UVa 784 - Maze Exploration
- UVA 784 - Maze Exploration
- UVa 784 - Maze Exploration
- uva 784 - Maze Exploration
- UVA 784 Maze Exploration
- uva 784 - Maze Exploration
- uva 784 - Maze Exploration
- UVA 784 Maze Exploration
- UVa 784 - Maze Exploration
- UVa 784 - Maze Exploration
- UVa 784 - Maze Exploration
- UVA 784 Maze Exploration
- UVA 784 Maze Exploration
- UVA - 784 Maze Exploration
- 【C#学习】yield关键字
- C#基础-008 赋值运算
- Scala高阶函数操作示例详解
- 二进制加减法
- 朴素贝叶斯分类器
- Maze Exploration UVA
- ServletConfig详解
- bzoj2946 [Poi2000]公共串(SA+二分答案 同poj3450)
- 理解jquery的$.extend()、$.fn和$.fn.extend()
- matlab2c使用c++实现matlab函数系列教程-blkdiag函数
- json数组生成器-jquery
- 算法的时间复杂度和空间复杂度-总结
- zcmu-1411
- zabbix的在线安装