Hdu---1010
来源:互联网 发布:mac系统怎么更新不了 编辑:程序博客网 时间:2024/06/07 04:53
深度优先搜索 迷宫-固定时间是否找到出口
#include<iostream>#include<string.h>#include<stdlib.h>using namespace std;char map[109][109];int n,m,t,di,dj;bool escape;int dir[4][2]= {{0,-1},{0,1},{1,0},{-1,0}};void dfs(int si,int sj,int cnt){ int i,temp; if(si>n||sj>m||si<=0||sj<=0) return; if(cnt==t&&si==di&&sj==dj) escape=1; if(escape) return; temp=(t-cnt)-abs(si-di)-abs(sj-dj);//奇偶性剪枝 if(temp<0||temp&1) return; for(i=0; i<4; i++) { if(map[si+dir[i][0]][sj+dir[i][1]]!='X') { map[si+dir[i][0]][sj+dir[i][1]]='X'; dfs(si+dir[i][0],sj+dir[i][1],cnt+1); map[si+dir[i][0]][sj+dir[i][1]]='.'; } } return;}int main(){ int i,j,si,sj; while(cin>>n>>m>>t) { if(n==0&&m==0&&t==0) break; int wall=0; for(i=1; i<=n; i++) for(j=1; j<=m; j++) { cin>>map[i][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]=='X') wall++; } if(n*m-wall<=t) { cout<<"NO"<<endl; continue; } escape=0; map[si][sj]='X'; dfs(si,sj,0); if(escape) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
0 0
- HDU 1010
- HDU 1010
- hdu 1010
- hdu 1010
- HDU 1010
- HDU 1010
- hdu 1010
- hdu-1010
- hdu 1010
- hdu 1010
- HDU 1010
- hdu 1010
- hdu 1010
- hdu-1010
- hdu-1010
- hdu 1010
- HDU 1010
- (1010)HDU
- iOS UIViewController的生命周期及iOS程序执行顺序
- MYSQL查询优化
- 用css写出横向导航栏
- 使用MIC进行变量选择
- 几何原本查询程序1.0
- Hdu---1010
- I'll play a trick on you
- ATOM特效显示
- 二分图强连通分量 tarjan 模板
- 2659: [Beijing wc2012]算不出的算式
- 质数的蛇形填数
- php逐行读取文件数据
- iOS 简单架构及运行流程
- 扫盲贴--关于IP地址那点事儿