hdu 1010 Tempter of the Bone(dfs)
来源:互联网 发布:韦德总决赛数据 编辑:程序博客网 时间:2024/05/24 01:44
题意:狗狗在S位置,门在D位置,让狗狗走到门那里要刚好用时T秒
#include <stdlib.h>#include <stdio.h>#include <math.h>int vis[10][10];char map[10][10];int n, m, t, i, j;int si, sj, ei, ej;bool flag;int dis[4][2]={{0,1},{0,-1},{1,0},{-1,0}};void dfs(int x, int y, int cnt){ int temp, i; if(x>n||y>m||x<=0||y<=0) return; if(x==ei&&y==ej&&cnt==t) { flag=1; return; } temp=t-cnt-abs(x-ei)-abs(y-ej);//剪枝 if(temp<0||temp%2) return; for(i=0; i<4; i++) { if(map[x+dis[i][0]][y+dis[i][1]]!='X') { map[x+dis[i][0]][y+dis[i][1]]='X'; dfs(x+dis[i][0], y+dis[i][1], cnt+1); if(flag) return ; map[x+dis[i][0]][y+dis[i][1]]='.'; } }}int main(){ while(scanf("%d%d%d", &n,&m,&t)&&n&&m&&t) { getchar(); flag=0; for(i=1; i<=n; i++) { for(j=1; j<=m; j++) { scanf("%c", &map[i][j]); if(map[i][j]=='S') { map[i][j]='X'; si=i, sj=j; } if(map[i][j]=='D') ei=i,ej=j; } getchar(); } dfs(si, sj, 0); if(flag) puts("YES"); else puts("NO"); } 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)
- 定制iOS 7中的导航栏和状态栏
- HDU 4722-Good Numbers
- stm32 RTC时间
- POJ 3384 半平面交
- 常用电脑的人该怎样保护眼睛
- hdu 1010 Tempter of the Bone(dfs)
- AfxWinMain中pThread->InitInstance()出错的解决方法
- 我是一个好人
- 笨小五 - 之工作笔录 android 返回键和菜单键
- UVa 10557 & HDU 1317 - XYZZY
- PID口诀
- CGI,FastCGI,PHP-CGI与PHP-FPM对比
- NYOJ 665 台球碰撞
- ThinkPad E431 获取无限网络的驱动