博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2251 Dungeon Master
阅读量:4356 次
发布时间:2019-06-07

本文共 2889 字,大约阅读时间需要 9 分钟。

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 43874   Accepted: 16554

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 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0

Sample Output

Escaped in 11 minute(s).Trapped!

Source

思路:宽搜。
#include
#include
#include
#include
#include
using namespace std;struct nond{ int x,y,z,tot; };queue
que;int map[31][31][31];int sx,sy,sz,tx,ty,tz;int dx[6]={ 1,-1,0,0,0,0};int dy[6]={ 0,0,1,-1,0,0};int dz[6]={ 0,0,0,0,1,-1};int n,m,k,ans=0x7f7f7f7f;void bfs(int x,int y,int z){ nond tmp;tmp.x=x;tmp.y=y;tmp.z=z;tmp.tot=0; que.push(tmp); while(!que.empty()){ nond now=que.front(); que.pop(); for(int i=0;i<6;i++){ int cx=now.x+dx[i]; int cy=now.y+dy[i]; int cz=now.z+dz[i]; int ctot=now.tot+1; if(cx==tx&&cy==ty&&cz==tz){ ans=min(ctot,ans); } if(cx>=1&&cx<=n&&cy>=1&&cy<=m&&cz>=1&&cz<=k&&!map[cx][cy][cz]){ map[cx][cy][cz]=1; nond c;c.x=cx;c.y=cy;c.z=cz;c.tot=ctot; que.push(c); } } }}int main(){ while(scanf("%d%d%d",&k,&n,&m)&&n!=0&&m!=0&&k!=0){ for(int c=1;c<=k;c++) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ char x;cin>>x; if(x=='#') map[i][j][c]=1; else map[i][j][c]=0; if(x=='S'){ sx=i;sy=j;sz=c; } if(x=='E'){ tx=i;ty=j;tz=c; } } map[sx][sy][sz]=1; bfs(sx,sy,sz); if(ans!=0x7f7f7f7f) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n");ans=0x7f7f7f7f; }}/*3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0*/

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/8830249.html

你可能感兴趣的文章
[POJ 2689] Prime Distance
查看>>
[ 原创 ] Linux下查找指定类型文件以及删除
查看>>
win10环境下jdk1.8+Android Developer Tools Build: v22.3.0-887826的问题
查看>>
辗转相除法求最大公约数
查看>>
Centos7 安装mysql5.7.16
查看>>
java串口通信与打卡器交互
查看>>
<CoreJava> 5.2 Object:所有类的超类
查看>>
输入年月日计算是星期几
查看>>
redis部分配置与报错解决
查看>>
Python Challenge(0-8)
查看>>
oracle中的trunc()函数
查看>>
对大一一年的总结和对大二的规划
查看>>
结构化程序设计04 - 零基础入门学习Delphi13
查看>>
密码学基础
查看>>
Java基础Map接口+Collections工具类
查看>>
OSGI基础知识整理
查看>>
Revit 开发将自己的窗口设置为Revit窗口
查看>>
倾斜摄影数据OSGB转换成3DML(转载)
查看>>
给年轻程序员的几句话
查看>>
ionic如何uglify和minify你的js,css,image,png....
查看>>