poj 2251 Dungeon Master
来源:互联网 发布:mac装win10鼠标不能用 编辑:程序博客网 时间:2024/06/05 12:40
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16089 Accepted: 6241
Description
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?
Is an escape possible? If yes, how long will it take?
Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0
Sample Output
Escaped in 11 minute(s).Trapped!
Source
Ulm Local 1997
一道简单的BFS只是方向改为6个 平面改为立体 定义三维数组即可 要求输出最短时间(没走一步加时一分钟 )及最短路径。。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ans,n,c,r;int sh,sx,sy;int eh,ex,ey;typedef class{ public: int h,r,c; int depth;}ZB;int map[40][40][40],vis[40][40][40];int bfs(int k,int x,int y){ ZB queue[30000]; int head,tail; queue[head=0].h=k; queue[tail=0].r=x; queue[0].c=y; queue[tail++].depth=1; vis[k][c][y]=1; while(head<tail) { ZB w=queue[head++]; if(w.h==eh&&w.r==ex&&w.c==ey) { ans=w.depth; return 1; } if(map[w.h][w.r][w.c-1]&&!vis[w.h][w.r][w.c-1])//西 { vis[w.h][w.r][w.c-1]=1; queue[tail].h=w.h; queue[tail].r=w.r; queue[tail].c=w.c-1; queue[tail++].depth=w.depth+1; } if(map[w.h][w.r-1][w.c]&&!vis[w.h][w.r-1][w.c])//北 { vis[w.h][w.r-1][w.c]=1; queue[tail].h=w.h; queue[tail].r=w.r-1; queue[tail].c=w.c; queue[tail++].depth=w.depth+1; } if(map[w.h][w.r][w.c+1]&&!vis[w.h][w.r][w.c+1])//东 { vis[w.h][w.r][w.c+1]=1; queue[tail].h=w.h; queue[tail].r=w.r; queue[tail].c=w.c+1; queue[tail++].depth=w.depth+1; } if(map[w.h][w.r+1][w.c]&&!vis[w.h][w.r+1][w.c])//南 { vis[w.h][w.r+1][w.c]=1; queue[tail].h=w.h; queue[tail].r=w.r+1; queue[tail].c=w.c; queue[tail++].depth=w.depth+1; } if(map[w.h+1][w.r][w.c]&&!vis[w.h+1][w.r][w.c])//下 { vis[w.h+1][w.r][w.c]=1; queue[tail].h=w.h+1; queue[tail].r=w.r; queue[tail].c=w.c; queue[tail++].depth=w.depth+1; } if(map[w.h-1][w.r][w.c]&&!vis[w.h-1][w.r][w.c])//上 { vis[w.h-1][w.r][w.c]=1; queue[tail].h=w.h-1; queue[tail].r=w.r; queue[tail].c=w.c; queue[tail++].depth=w.depth+1; } } return 0;}int main(){ int i,j,k; char wz; while(cin>>n>>r>>c,n&&r&&c) { memset(vis,0,sizeof(vis)); memset(map,0,sizeof map); for(k=1;k<=n;k++) for(i=1;i<=r;i++) for(j=1;j<=c;j++) { cin>>wz; if(wz=='S') { map[k][i][j]=1; sh=k;sx=i;sy=j; } else if(wz=='E') { map[k][i][j]=1; eh=k;ex=i;ey=j; } else if(wz=='.') map[k][i][j]=1; } /* for(k=0;k<n;k++) {for(i=0;i<r;i++) {for(j=0;j<c;j++) cout<<map[k][i][j]; cout<<endl; } cout<<endl; }*/ if(bfs(sh,sx,sy)) cout<<"Escaped in "<<ans-1<<" minute(s)."<<endl; else cout<<"Trapped!"<<endl; } return 0;}
4 1
- 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
- (*(volatile unsigned int *))详解-数值常量如何转化为内存地址_转阿拉丁神丢新浪博
- spring mvc 给action添加事务不成功的原因
- 从四大维度看O2O与传统电商的不同 作者: 黄渊普
- 5.7.4 非静态数据初始化
- Block使用中的一些疑问解答(包括循环引用问题的解决)
- poj 2251 Dungeon Master
- 剑指offer 面试题10 二进制中1的个数
- Linux下获取详细硬件信息Dmidecode,BIOS、系统、主板、处理器、内存、缓存等信息
- 硬件发展趋向软件
- 华为地铁换乘问题
- Android开机动画 (boot animation)制作
- 第一篇日志
- 如何从linux内核--ubuntu系统cmdline上预留DDR物理内存DMA--mem=750M
- nginx 通过upstream实现与多个php-fpm进程通信