poj 2251 Dungeon Master
来源:互联网 发布:淘宝掌中宝是什么 编辑:程序博客网 时间:2024/04/26 05:47
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 36311 Accepted: 13837
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!
题目大意:
这个题目是一个三维的空间图形,#不能通行,.可以通行,每走一步花费一分钟的时间,问从S到E最短需要多长时间,不能到达
输出Trapped!题目解析:这是一个简单的BFS题代码:#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int maxn=35;char node[maxn][maxn][maxn];int vis[maxn][maxn][maxn];int dir[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};int x,y,z;int ex,ey,ez,ok;struct trip{ int x; int y; int z; int step;};int check(int p,int r,int s){ if(p<0||p>=x||r<0||r>=y||s<0||s>=z||node[p][r][s]=='#') return 1; return vis[p][r][s];}void BFS(int p,int r,int s){ trip a,next; queue<trip>q; a.x=p; a.y=r; a.z=s; a.step=0; q.push(a); while(!q.empty()) { a=q.front(); q.pop(); if(a.x==ex&&a.y==ey&&a.z==ez) { cout<<"Escaped in "<<a.step<<" minute(s)."<<endl; ok=1; break; } for(int i=0;i<6;i++) { next.x=a.x+dir[i][0]; next.y=a.y+dir[i][1]; next.z=a.z+dir[i][2]; if(check(next.x,next.y,next.z)) continue; next.step=a.step+1; vis[next.x][next.y][next.z]=1; q.push(next); } }}int main(){ //freopen("in.txt","r",stdin); while(cin>>x>>y>>z&&x&&y&&z) { ok=0; memset(node,0,sizeof(node)); memset(vis,0,sizeof(vis)); for(int i=0;i<x;i++) for(int j=0;j<y;j++) cin>>node[i][j]; for(int i=0;i<x;i++) for(int j=0;j<y;j++) for(int k=0;k<z;k++) if(node[i][j][k]=='E') { ex=i; ey=j; ez=k; break; } for(int i=0;i<x;i++) for(int j=0;j<y;j++) for(int k=0;k<z;k++) if(node[i][j][k]=='S') BFS(i,j,k); if(!ok) cout<<"Trapped!"<<endl; } return 0;}
阅读全文
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
- ARM异常处理
- AIX操作系统及常用命令
- 游戏开发中的人工智能(完):遗传算法
- android.content.ActivityNotFoundException异常
- 用html5自带表单验证 并且用ajax提交的解决方法(附例子)
- poj 2251 Dungeon Master
- Java并发之CountDownLatch、CyclicBarrier和Semaphore
- TCP的三次握手和四次挥手
- 算法-->阶乘
- KMP算法实现
- 数据库查询引擎
- 马云又一大动作_天猫汽车自动贩售机横空出世。
- bzoj1295: [SCOI2009]最长距离
- ModBus RTU协议 16 位CRC校验方式最简实现