【DFS】hdu 1010 Tempter of the Bone(迷宫)
来源:互联网 发布:淘宝网店怎么关闭 编辑:程序博客网 时间:2024/05/17 23:59
http://acm.hdu.edu.cn/showproblem.php?pid=1010
分析:主要是正好在T时间到达
迷宫类输入时需要注意,x,y的边界范围
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int N,M,Si,Sj,Di,Dj,flag,T;int a[4][2]={0,1,0,-1,-1,0,1,0};char str[10][10];void DFS(int x,int y,int ans){if(x==Di&&y==Dj&&T==ans) flag=1;if(flag) return;int t=T-ans-abs(x-Di)-abs(y-Dj);//奇偶剪枝if(t<0||t%2!=0) return;for(int i=0;i<4;i++){int x1=x+a[i][0],y1=y+a[i][1];if(x1<N&&x1>=0&&y1<M&&y>=0&&str[x1][y1]!='X')//{str[x1][y1]='X';BFS(x1,y1,ans+1);str[x1][y1]='.';}}}int main(){int i,j,count;while(scanf("%d%d%d",&N,&M,&T)&&N||M||T){count=0;for(i=0;i<N;i++)//X-N{scanf("%s",str[i]);for(j=0;j<M;j++)//Y-M{if(str[i][j]=='S')Si=i,Sj=j;else if(str[i][j]=='D')Di=i,Dj=j;else if(str[i][j]=='X')count++;}}flag=0;str[Si][Sj]='X';if(N*M-count<T)//可走'.'总数<T {printf("NO\n");continue;}DFS(Si,Sj,0);if(flag) printf("YES\n");else printf("NO\n");}return 0;}
- 【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 (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
- Unable to execute dex: Multiple dex files define Lcom
- hdu 4374 One hundred layer
- ASP.NET AJAX之UpdatePanel 和JQUERY冲突
- ACCESS数据库局域网内实现多机数据共享的方法
- MFC中UpdateData()函数的使用
- 【DFS】hdu 1010 Tempter of the Bone(迷宫)
- matlab注释方法
- 赫夫曼编码和实现
- 未解决的正则表达式
- OpenStack Host Aggregation用例分析 (H版)
- hdu 1042 N!
- 循环队列的实现和操作
- [bzoj1003] [ZJOI2006]物流运输trans
- 老婆,对不起