hdu 1010 Tempter of the Bone
来源:互联网 发布:freebsd下载软件 编辑:程序博客网 时间:2024/06/06 18:49
点击打开链接
#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++){inttx=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;}
0 0
- 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
- 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
- hdu 1010 Tempter of the Bone
- 最短路poj 1125
- ural 1880. Psych Up's Eigenvalues
- 怎么将excel在线转换pdf
- Object-C 的特点
- 杭电 1150 moving tables
- hdu 1010 Tempter of the Bone
- cocos2d-x 使用box2d来做碰撞检测(且仅用来做碰撞检测)
- HTTP Keep-Alive模式
- hust NENU Summer Training 2014 #2 D - Polyomino Decomposer
- 树莓派的FTP配置
- 广度优先搜索
- 如何将PDF转换成PPT演示文稿
- HDUJ 2031 进制转换
- 指针数组和数组指针