POJ - 2251 - Dungeon Master
2017-08-10 12:19
363 查看
Dungeon Master
DescriptionYou 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 andthe maze is surrounded by solid rock on all sides. Is an escape possible? If yes, how long will it take? InputThe 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 theexit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.OutputEach 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
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 36727 | Accepted: 14020 |
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0Sample Output
Escaped in 11 minute(s). Trapped!
三维的BFS,与二维差别不大。
#include<iostream>#include<algorithm>#include<queue>#include<cstdio>#include<cstring>#include<stack>#include<cmath>using namespace std;struct AP{int x,y,h,flag;};AP func3(int h,int x,int y,int flag){AP t;t.x=x;t.y=y;t.h=h;t.flag=flag;return t;}int main(){int h,n,m;while(cin>>h>>n>>m&&(h!=a2990||m!=0||n!=0)){int map[40][40][40]= {};AP str;for(int i=1; i<=h; i++)for(int j=1; j<=n; j++)for(int k=1; k<=m; k++){char c;cin>>c;if(c=='S')str=func3(i,j,k,0);if(c=='.')map[i][j][k]=1;if(c=='E')map[i][j][k]=2;}queue<AP>que1;que1.push(str);int com[18]= {1,0,0,-1,0,0,0,-1,0,0,1,0,0,0,1,0,0,-1},vjudge=0;while(que1.size()){AP temp=que1.front();que1.pop();for(int i=0; i<6; i++)if(map[temp.h+com[3*i]][temp.x+com[3*i+1]][temp.y+com[3*i+2]]){if(map[temp.h+com[3*i]][temp.x+com[3*i+1]][temp.y+com[3*i+2]]==2){vjudge=1;printf("Escaped in %d minute(s).\n",temp.flag+1);break;}map[temp.h+com[3*i]][temp.x+com[3*i+1]][temp.y+com[3*i+2]]=0;que1.push(func3(temp.h+com[3*i],temp.x+com[3*i+1],temp.y+com[3*i+2],temp.flag+1));}if(vjudge)break;}if(!vjudge)cout<<"Trapped!"<<endl;}return 0;}
相关文章推荐
- POJ 2251 Dungeon Master(简单BFS)
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- poj_2251 Dungeon Master(bfs)
- POJ 2251-Dungeon Master【简单搜索】
- POJ - 2251 Dungeon Master (三维bfs)
- POJ 2251 Dungeon Master(BFS)
- POJ 2251 Dungeon Master(bfs)
- POJ 2251 Dungeon Master (BFS)
- POJ 2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master(搜索BFS)
- poj 2251 Dungeon Master
- POJ-2251-Dungeon Master
- poj2251 Dungeon Master
- POJ 2251 Dungeon Master (三维迷宫 BFS)
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master (BFS 三维)
- POJ 2251 Dungeon Master(BFS+数据读取)
- POJ 2251 Dungeon Master 比较有趣的三维迷宫bfs搜索路径
- Dungeon Master(poj 2251)