POJ 2251 - Dungeon Master
2016-01-05 10:57
302 查看
B - Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status
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?
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.
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
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
Sample Output
三维BFS练手:
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status
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?
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.
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
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 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample Output
Escaped in 11 minute(s). Trapped!
三维BFS练手:
#include<iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; struct point{ int x,y,z,step; point(){} point(int xx,int yy,int zz,int ss):x(xx),y(yy),z(zz),step(ss){} }; #define N 35 int a ; bool vis ; int l,r,c; int ex,ey,ez; int vx[]={1,0,-1,0,0,0}; int vy[]={0,-1,0,1,0,0}; int vz[]={0,0,0,0,1,-1}; int main(){ while (scanf("%d%d%d",&l,&r,&c)!=EOF){ queue<point> q; if (l==0 && r==0 && c==0) break; memset(vis,false,sizeof(vis)); memset(a,0,sizeof(a)); for (int i=1;i<=l;i++){ for (int j=1;j<=r;j++){ getchar(); for (int k=1;k<=c;k++){ char c=getchar(); if (c=='S'){ a[i][j][k]=0; q.push(point(i,j,k,0)); //printf("start %d %d %d\n",i,j,k); }else if (c=='#'){ a[i][j][k]=0; }else if (c=='.'){ a[i][j][k]=1; }else{ a[i][j][k]=1; ex=i; ey=j; ez=k; } } } getchar(); } //printf("%d %d %d\n",ex,ey,ez); point now; int x,y,z,step; while (!q.empty()){ now=q.front(); q.pop(); x=now.x,y=now.y,z=now.z,step=now.step; if (ex==x && ey==y && ez==z) break; for (int i=0;i<6;i++){ int tx=x+vx[i]; int ty=y+vy[i]; int tz=z+vz[i]; if (a[tx][ty][tz]){ a[tx][ty][tz]=0; q.push(point(tx,ty,tz,step+1)); } } } if (ex==x && ey==y && ez==z){ printf("Escaped in %d minute(s).\n",step); }else{ printf("Trapped!\n"); } } return 0; }
相关文章推荐
- VS2010宏注释运行后没有效果
- Hammer.js 手势事件
- ListCtrl设置单个单元格颜色的实现 .
- IOS数据库FMDB增、删、改、查的使用
- Android API Level 对应关系 6.0
- xxx is not in the sudoers file. This incident will be reported
- javascript 继承
- 使用ajax和history.pushState无刷新改变页面URL(转)
- 【C#】使用Windows身份验证连接Sql Server,ListView随窗体大小的变化而调节列宽
- jQuery Validation Engine Ajax验证
- DNS中的MaxCacheEntryTtlLimit和NegativeCacheTime
- android preferences使用
- hibernate注解验证
- 微服务介绍与优缺点分析
- grep 使用杂技
- python安装集成包
- 为什么写Java程序需要接口
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决办法
- window下git服务器搭建
- [COPY]LBS的瓶颈和方案