POJ 2251 Dungeon Master
来源:互联网 发布:淘宝推广大师下载 编辑:程序博客网 时间:2024/06/06 00:36
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 29345 Accepted: 11397
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!
题解:题意很简单,不提了……就是一个三维地宫……
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<stdlib.h>#include<time.h>#include<math.h>#include<queue>#include<stack>#include <iostream>#define mem(a) memset(a,0,sizeof(a))using namespace std;char map[32][32][32];bool v[32][32][32];int d[6][3]= {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,-1},{0,0,1}};int n,m,r,a,b,c;struct node{ int x,y,z,s;};int check(int x,int y,int z){ if(x>=0&&x<n&&y>=0&&y<m&&z>=0&&z<r&&map[x][y][z]!='#'&&!v[x][y][z]) return 1; return 0;}void bfs(){ queue<node>q; node start,next; mem(v); start.x=a,start.y=b,start.z=c,start.s=0; q.push(start); v[a][b][c]=true; while(!q.empty()) { start=q.front(); q.pop(); for(int i=0; i<6; i++) { next.x=start.x+d[i][0],next.y=start.y+d[i][1],next.z=start.z+d[i][2],next.s=start.s+1; if(check(next.x,next.y,next.z)) { if(map[next.x][next.y][next.z]=='E') { printf("Escaped in %d minute(s).\n",next.s); return; } v[next.x][next.y][next.z]=true; q.push(next); } } } printf("Trapped!\n"); return;}int main(){ while(~scanf("%d%d%d",&n,&m,&r),n,m,r) { for(int i=0; i<n; i++) for(int j=0; j<m; j++) scanf("%s",map[i][j]); for(int i=0; i<n; i++) for(int j=0; j<m; j++) for(int k=0; k<r; k++) if(map[i][j][k]=='S') a=i,b=j,c=k; bfs(); }}
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
- Android学习-传感器的使用
- op的压摆率和增益带宽积的选择
- 17 - 04 - 14 Web安全(10)
- 删除指定节点的两种方法
- 最优化学习笔记(十八)——拟牛顿法(4)DFP算法
- POJ 2251 Dungeon Master
- 基于Bootstrap的Java开发问题总结
- AngularJS最理想开发工具WebStorm
- LTE基础技术及协议帧结构
- centos7 u盘安装
- 动画 Android
- MARKDOWN 数学符号
- MSP430数码管的使用Ⅲ
- 价值6万元的excel教程