hdu 1010 Tempter of the Bone
2014-07-19 09:16
309 查看
点击打开链接
#include<stdio.h> #include<string.h> char map[9][9]; int v[9][9],m,n,tim,si,sj,di,dj,flag; int d[4][2]={0,1,0,-1,1,0,-1,0}; int abs(int a) { if(a<0) return -a; return a; } void dfs(int x,int y,int ti) { int i,j,step; if(x==di&&y==dj&&ti==tim) { flag=1;return ; } if(flag||ti>=tim)return ; step=(tim-ti)-(abs(di-x)+abs(dj-y)); if(step%2||step<0) return ; for(i=0;i<4;i++) { int tx=x+d[i][0]; int ty=y+d[i][1]; if(tx<0||tx>=n||ty>=m||ty<0||map[tx][ty]=='X'||v[tx][ty]) continue; v[tx][ty]=1; dfs(tx,ty,ti+1); v[tx][ty]=0; } } int main() { int i,j,num; while(scanf("%d%d%d",&n,&m,&tim),m+n+tim) { memset(v,0,sizeof(v)); num=0;flag=0; for(i=0;i<n;i++) { scanf("%s",map[i]); for(j=0;j<m;j++) { if(map[i][j]=='S') si=i,sj=j; else if(map[i][j]=='D') di=i,dj=j; else if(map[i][j]=='.') num++; } } if(num<tim-1) { printf("NO\n"); continue; } if((abs(di-si)+abs(dj-sj)+tim)%2) { printf("NO\n"); continue; } v[si][sj]=1; dfs(si,sj,0); if(flag)printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- hdu1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone
- 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
- zoj 2110(hdu 1010)Tempter of the Bone(深搜)
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- 迷宫 hdu 1010 Tempter of the Bone
- Hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(搜索+剪枝)
- HDU 1010 Tempter of the Bone(DFS)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone