POJ 2251 Dungeon Master(三维BFS)
来源:互联网 发布:网络智能机顶盒价格 编辑:程序博客网 时间:2024/06/18 14:07
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 39408 Accepted: 14987
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!
思路:比二维多了2个方向。
代码:
#include<stdio.h>#include<string.h>#include<iostream>#include<queue>using namespace std;char map_1[35][35][35];int map_2[35][35][35],mov[6][3]={1,0,0,0,1,0,0,0,1,-1,0,0,0,-1,0,0,0,-1};struct note{ int s,x,y,cnt;}st,d;int main(){ int L,R,C,i,j,k; char a; while(scanf("%d%d%d",&L,&R,&C),L+R+C){ for(i=0;i<L;i++){ for(j=0;j<R;j++){ scanf("%s",map_1[i][j]); for(k=0;k<C;k++){ a=map_1[i][j][k]; map_2[i][j][k]=0; if(a=='#')map_2[i][j][k]=1; else if(a=='S'){ st.s=i; st.x=j; st.y=k; st.cnt=0; map_2[i][j][k]=1; } } } }// for(i=0;i<L;i++){// for(j=0;j<R;j++){// for(k=0;k<C;k++)// printf("%d ",map_2[i][j][k]);// printf("\n");// }// printf("\n");// } queue<note> q; q.push(st); int flag=0; while(!q.empty()){ st=q.front(); q.pop(); for(i=0;i<6;i++){ d.s=st.s+mov[i][0]; d.x=st.x+mov[i][1]; d.y=st.y+mov[i][2]; d.cnt=st.cnt+1; if(d.s<0||d.s>=L||d.x<0||d.x>=R||d.y<0||d.y>=C||map_2[d.s][d.x][d.y])continue; if(map_1[d.s][d.x][d.y]=='E'){ flag=1; break; } map_2[d.s][d.x][d.y]=1; q.push(d); } if(flag)break; } if(flag)printf("Escaped in %d minute(s).\n",d.cnt); else printf("Trapped!\n"); } return 0;}
阅读全文
0 0
- 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
- poj 2251 Dungeon Master(三维BFS)(中等)
- poj 2251 Dungeon Master(BFS三维)
- POJ 2251 Dungeon Master(三维bfs)
- POJ 2251 Dungeon Master(三维bfs)
- <三维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)
- POJ 2251(WA)Dungeon Master(三维BFS)
- POJ.2251 Dungeon Master (三维BFS)
- poj 2251Dungeon Master(三维bfs)
- HashMap、LinkedHashMap、ConcurrentHashMap、ArrayList、LinkedList的底层实现。
- url
- 在Eclipse中使用JUnit4进行单元测试(初级篇)
- CSS相关属性的理解和一些效果的实现
- 在Power BI桌面版本中使用DirectQuery
- POJ 2251 Dungeon Master(三维BFS)
- ZooKeeper在大型分布式系统中的应用之Hadoop。
- Cyclic Nacklace
- 工业网络的物理隔离与数据采集
- 使用 fastjson将字符串转为 list<map<string,object>>
- 国内外交互体验很好的十款验证码
- Java设计模式之建造者模式
- pandas中如何索引到某一列的特定值
- 深度探讨验证码发展史,账户中心安全科普文