HDU 1010 Tempter of the Bone (DFS)
来源:互联网 发布:qq表情生成软件 编辑:程序博客网 时间:2024/05/21 00:52
//题意自己看,不会度娘
#include <stdio.h>#include <math.h>#include <string.h>char map[10][10];int si,sj,di,dj,is,T,n,m,word;int dx[]={-1,0,1,0};int dy[]={0,1,0,-1};//四个方向void DFS(int di,int dj,int t){int i;if(di<1||dj<1||di>n||dj>m||T<t||is)//排除部分不可能情况 return;if(si==di&&sj==dj&&t==T)//成功到达 {is=1;return;}if((abs(di-si)+abs(dj-sj))%2!=(T-t)%2)return;//根据步数来剪枝(狗走到门的时间必须和题目给定的时间是同奇同偶的,否则也不能在指定的那秒到达门,也不可能得逃出。)for(i=0;i<4;i++){if(map[di+dx[i]][dj+dy[i]]!='X')//非墙,可走{map[di+dx[i]][dj+dy[i]]='X';//当前设为墙,表示已走过 DFS(di+dx[i],dj+dy[i],t+1);//继续走下去 map[di+dx[i]][dj+dy[i]]='.';//回朔 } }return;}int main(int argc, char *argv[]){int i,j;while(scanf("%d %d %d",&n,&m,&T)!=EOF) {if(n==0&&m==0&&T==0)break;word=0;getchar();for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%c",&map[i][j]);if(map[i][j]=='S')//开始 {di=i;dj=j;} if(map[i][j]=='D')//门 {si=i;sj=j;}if(map[i][j]=='X')//墙 {word++;}}getchar();}is=0;if(n*m-word<T)is=0;//可走的路小于时间,必败 else{map[di][dj]='X';DFS(di,dj,0);}if(is==1)printf("YES\n");elseprintf("NO\n"); }return 0;}
//Start-ZJ
阅读全文
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)
- IFeatureLayerDefinition接口实现IFeatureLayer图层显示过滤,图层全范围视图的获取
- laytpl--前端数据绑定 (示例)
- 敏感词查询过滤DFA算法
- Horizontal+异步+pullTorefresh+viewPager+侧滑(XListView)
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
- HDU 1010 Tempter of the Bone (DFS)
- 关于CarbonData+Spark SQL的一些应用实践和调优
- Android 通知栏
- 友好城市(动态规划,排序)
- 《小马SpringBoot框架》介绍与安装
- Docker下HBase学习,三部曲之一:极速体验
- 去上海面试Java外包工作的郁闷
- PAT 甲级 1013. Battle Over Cities (25)
- docker部署php+nginx环境