POJ
来源:互联网 发布:三菱plc编程软件 编辑:程序博客网 时间:2024/06/05 15:34
题目链接:http://poj.org/problem?id=2251点击打开链接
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 36049 Accepted: 13741
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 <iostream>#include <queue>#include <stdio.h>#include <stdlib.h>#include <stack>#include <limits.h>#include <string>#include <string.h>#include <vector>#include <set>#include <map>#include <algorithm>#include <math.h>using namespace std;char mmap[33][33][33];int book[33][33][33];struct xjy{ int x,y,z;};xjy b,e;queue <xjy > q;int dir[6][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};void bfs(){ while(!q.empty()) q.pop(); q.push(b); while(!q.empty()) { xjy mid=q.front(); q.pop(); if((mid.x==e.x)&&(mid.y==e.y)&&(mid.z==e.z)) { break; } for(int i=0;i<6;i++) { xjy midmid; midmid.x=mid.x+dir[i][0]; midmid.y=mid.y+dir[i][1]; midmid.z=mid.z+dir[i][2]; if(mmap[midmid.x][midmid.y][midmid.z]!='#'&&(book[mid.x][mid.y][mid.z]+1)<book[midmid.x][midmid.y][midmid.z]) { q.push(midmid); book[midmid.x][midmid.y][midmid.z]=book[mid.x][mid.y][mid.z]+1; } } }}int main(){ int n,m,k; while(~scanf("%d%d%d",&n,&m,&k)&&(n||m||k)) { getchar(); memset(mmap,'#',sizeof(mmap)); for(int i=0;i<=30;i++) { for(int j=0;j<=30;j++) { for(int l=0;l<=30;l++) book[i][j][l]=INT_MAX; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int l=1;l<=k;l++) { scanf("%c",&mmap[i][j][l]); if(mmap[i][j][l]=='S') { b.x=i; b.y=j; b.z=l; book[i][j][l]=0; } else if(mmap[i][j][l]=='E') { e.x=i; e.y=j; e.z=l; } }getchar(); }getchar(); } bfs(); if( book[e.x][e.y][e.z] ==INT_MAX) cout << "Trapped!" << endl; else cout << "Escaped in " << book[e.x][e.y][e.z] << " minute(s)." << endl; }}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 对SQL_Server 部分知识的回顾
- 继承与多态的区别
- 【微信开发】定制消息推送
- Android Monkey日志自动分析脚本
- Cordova插件之支付整理
- POJ
- 【 Python进阶】python strip() split()函数实战
- github(To prevent you from losing history, non-fast-forward updates were rejected)
- Spring xmlDI和注解
- c++常用头文件
- springboot系列之一——springboot入门
- words Deom总结
- JS错误与调试
- 图片轮播