poj Dungeon Master
来源:互联网 发布:勤哲软件 编辑:程序博客网 时间:2024/06/03 13:16
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 20972 Accepted: 8137
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
//只不是把二维的坐标变成了三维坐标,多了两个方向,参考代码如下:
#include<stdio.h>#include<iostream>#include<string.h>#include<queue>using namespace std;char mp[35][35][35];int vis[35][35][35],dis[35][35][35];int dx[6]={0,0,-1,1,0,0};int dy[6]={0,0,0,0,1,-1};int dz[6]={1,-1,0,0,0,0}; int n,m,l;struct node{int x,y,z,d;friend bool operator < (node a,node b){return a.d>b.d; }}s,t,num;void bfs(int x,int y,int z){memset(dis,0,sizeof(dis));memset(vis,0,sizeof(vis));priority_queue<node> q;t.x=x; t.y=y; t.z=z; t.d=0;vis[x][y][z]=1; q.push(t);while(!q.empty()){s=q.top();q.pop();for(int i=0;i<6;i++){int a=s.x+dx[i];int b=s.y+dy[i];int c=s.z+dz[i];if(a>=1&&b>=1&&c>=1&&a<=n&&b<=m&&c<=l&&mp[a][b][c]!='#'&&!vis[a][b][c]){vis[a][b][c]=1;dis[a][b][c]=dis[s.x][s.y][s.z]+1;num.x=a; num.y=b; num.z=c;num.d=dis[a][b][c];q.push(num);}}}}int main(){int i,j,k,sx,sy,sz,ex,ey,ez;while(scanf("%d%d%d",&l,&n,&m),l+n+m){for(k=1;k<=l;k++)for(i=1;i<=n;i++)for(j=1;j<=m;j++){cin>>mp[i][j][k];if(mp[i][j][k]=='S'){sx=i; sy=j; sz=k;}if(mp[i][j][k]=='E'){ex=i; ey=j; ez=k;}}bfs(sx,sy,sz);if(dis[ex][ey][ez]!=0)printf("Escaped in %d minute(s).\n",dis[ex][ey][ez]);elseprintf("Trapped!\n");}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
- UVa 11054 Wine trading (贪心)
- iOS UI07_导航视图控制器
- 面试题2
- hdu 1429 胜利大逃亡(续) (bfs + 状态压缩)
- Java - Thinking in Java 第8章 习题
- poj Dungeon Master
- 开源 java CMS - FreeCMS2.3字典管理
- 陕西信合签名控件不能安装问题
- qdbuscpp2xml工具用法中输入和输入
- 黑马程序员————java基础之线程
- POJ___3126Prime Path
- JavaScript权威指南_150_第16章_脚本化CSS_16.0-概述
- [IOS]今天开始学UI---UISegmentedControl&&UIStepper
- 微调控件Spinner