Dungeon Master POJ 2251
来源:互联网 发布:鹿晗性格知乎分析 编辑:程序博客网 时间:2024/06/12 01:26
开始用dfs超时,然后改为bfs
题目http://poj.org/problem?id=2251
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<queue>using namespace std;char a[35][35][35];//迷宫 int L,R,C,vis[35][35][35];int dx[6]={-1,1,0,0,0,0};int dy[6]={0,0,-1,1,0,0};int dz[6]={0,0,0,0,-1,1};struct node{int x,y,z;int dis;//所花费的时间 };int check(int z,int x,int y){if(z<0||x<0||y<0||z>=L||x>=R||y>=C) return 0;if(vis[z][x][y]) return 0;if(a[z][x][y]=='#') return 0;return 1;}int bfs(int z,int x,int y){if(a[z][x][y]=='E'){return 1;}queue<node>q;struct node p,t;p.x=x;p.z=z;p.y=y;p.dis=0;q.push(p);while(!q.empty()){t=q.front();q.pop();if(a[t.z][t.x][t.y]=='E'){return t.dis;}for(int i=0;i<6;i++){ int nz=t.z+dz[i]; int nx=t.x+dx[i]; int ny=t.y+dy[i]; if(check(nz,nx,ny)){ vis[nz][nx][ny]=1; p.x=nx;p.z=nz;p.y=ny; p.dis=t.dis+1; q.push(p); } }}return 0;}int main(){scanf("%d%d%d",&L,&R,&C);//getchar();int sx,sy,sz,ex,ey,ez;while(L||R||C){memset(vis,0,sizeof(vis));for(int i=0;i<L;i++){getchar();for(int j=0;j<R;j++){for(int k=0;k<C;k++){scanf("%c",&a[i][j][k]);if(a[i][j][k]=='S'){sx=j;sy=k;sz=i;}if(a[i][j][k]=='E'){ex=j;ey=k;ez=i;}}getchar();//cout<<'$'<<endl;}//cout<<'%'<<endl;}//cout<<sz<<' '<<sx<<' '<<sy<<endl;vis[sz][sx][sy]=1;int flag=bfs(sz,sx,sy);if(flag){printf("Escaped in %d minute(s).\n",flag);}else{printf("Trapped!\n");}scanf("%d%d%d",&L,&R,&C);}}
0 0
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- Poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- POJ 2251Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 - Dungeon Master
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- poj 2251 Dungeon Master
- 安卓入门--Activity跳转页面
- I2C总线协议
- jeesite图片路径去掉“|” 只能上传单个图片
- vim粘贴复制学习
- Codeforces Gym 100971M Decomposition into Good Strings DP+数据结构
- Dungeon Master POJ 2251
- [GDOI2016]机密网络
- 函数模板 类模板
- JVM(二)——自动内存管理机制
- CKEditor实现图片上传以及预览
- Java的个人总结
- Git merge 与 rebase 区别
- Android源码在线阅读网站
- Linux 文件系统ext2, ext3, ext4