HDU 1010 Tempter of the Bone(DFS)
来源:互联网 发布:上海大型网络工程公司 编辑:程序博客网 时间:2024/04/29 22:41
题意:判断,能否从S到D,恰好在T时间到。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=10;int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};char map[maxm][maxm];int vis[maxm][maxm];int x1,y1;int m,n,T;int ok;void dfs(int x,int y,int step){ if(ok||step>T) { return; } else if(map[x][y]=='D'&&step==T) { ok=1; return; } for(int i=0;i<4;i++) { int sx=x+dir[i][0]; int sy=y+dir[i][1]; if(sx>=0&&sx<m&&sy>=0&&sy<n&&!vis[sx][sy]&&map[sx][sy]!='X') { vis[sx][sy]=1; dfs(sx,sy,step+1); vis[sx][sy]=0; } }}int main(){ while(scanf("%d%d%d",&m,&n,&T)!=EOF&&(m+n+T)) { memset(vis,0,sizeof(vis)); for(int i=0;i<m;i++) { scanf("%s",map[i]); for(int j=0;j<n;j++) { if(map[i][j]=='S') { x1=i; y1=j; } } } ok=0; vis[x1][y1]=1; dfs(x1,y1,0); if(ok) { printf("YES\n"); } else { printf("NO\n"); } } return 0;}
0 0
- HDU 1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone( DFS )
- HDU-1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone 【DFS】
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone(dfs)
- hdu 1010 Tempter of the Bone(DFS)
- dfs hdu 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone[dfs]
- [HDU 1010] Tempter of the Bone DFS
- HDU 1010 Tempter of the Bone(DFS)
- HDU 1010 Tempter of the Bone(DFS)
- hdu 1010 Tempter of the Bone dfs
- hdu 1010Tempter of the Bone(DFS)
- HDU-1010-Tempter of the Bone【DFS】
- hdu-1010Tempter of the Bone-dfs
- hdu 1010 Tempter of the Bone (dfs)
- HDU 1010 Tempter of the Bone(dfs)
- 什么是SDK? Software Development Kit
- 第四周项目3 单链表的应用
- 大杂烩——提升效率的技能
- Android Studio Tips -- 布局预览
- (1.5.2.12)字符串循环移位 编程之美3.1
- HDU 1010 Tempter of the Bone(DFS)
- IOS推送 原理及其小知识
- Hammer.js
- 第六周项目2-建立链栈算法库
- LeetCode----Combinations
- 第4周项目3 - 单链表应用(2)
- Android Studio Tips -- 自定义Logcat
- R语言运行环境
- 本地映射服务TUNNEL