AYIT606第七周周赛(3维广搜+队列) D - Dungeon Master地下勇士
来源:互联网 发布:java开发电商平台 编辑:程序博客网 时间:2024/04/30 18:15
D - Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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!
发现队列是一个很好地算法,很多问题通过队列去解决就变得没有那么复杂,是一个值得我好好去研究练习的算法。
这个题目的难度在于三维空间,不好去理解题意,分析去它的坐标变化,然后用结构体,三维数组,队列去处理,问题就好办多了!
#include<stdio.h>#include<queue>#include<string.h>using namespace std;struct data{ int x,y,z,step;} pre,cur;int flag,n,m,k,sx,sy,sz,v[120][120][120];char map[110][110][110];int dis[6][3]= {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};void BFS(){ queue<data>que; cur.x=sx; cur.y=sy; cur.z=sz; cur.step=0; que.push(cur); v[sx][sy][sz]=1; while(!que.empty()) { cur=que.front(); que.pop(); if(map[cur.x][cur.y][cur.z]=='E') { flag=1; printf("Escaped in %d minute(s).\n",cur.step); return ; } for(int i=0; i<6; i++) { pre=cur; pre.x+=dis[i][0]; pre.y+=dis[i][1]; pre.z+=dis[i][2]; if(pre.x>=0&&pre.x<n&&pre.y>=0&&pre.y<m&&pre.z>=0&&pre.z<k&&!v[pre.x][pre.y][pre.z]&&map[pre.x][pre.y][pre.z]!='#') { pre.step+=1; v[pre.x][pre.y][pre.z]=1; que.push(pre); } } }}int main(){ while(scanf("%d%d%d",&n,&m,&k)!=EOF) { if(!n&&!m&&!k) break; memset(v,0,sizeof(v)); for(int i=0; i<n; i++) for(int j=0; j<m; j++) { scanf("%s",&map[i][j]); for(int s=0; s<k; s++) if(map[i][j][s]=='S') { sx=i; sy=j; sz=s; } } flag=0; BFS(); if(!flag) printf("Trapped!\n"); } return 0;}
0 0
- AYIT606第七周周赛(3维广搜+队列) D - Dungeon Master地下勇士
- AYIT606第七周周赛(动态规划) A - How many ways
- AYIT606第七周周赛 B - 六度分离
- OpenJudge 2.5-1253 地下城大师(Dungeon Master)
- Dungeon Master (简单广搜)三维地下城
- POJ2251 Dungeon Master(3D迷宫 bfs)
- poj 2251 — Dungeon Master (3D + BFS)
- AYIT606第六周周六赛 (多重背包) E - Cash Machine 自动取款机
- 【POJ】2251 - Dungeon Master(dfs + 队列)
- 【POJ】-2251-Dungeon Master(BFS+队列)
- POJ2251:Dungeon Master(BFS)3D搜索
- NYOJ 353 3D dungeon + zoj 1940 Dungeon Master
- 浅谈成功运营12年的传奇2D游戏DNF(地下城与勇士)
- poj 2251 Dungeon Master(优先队列bfs)
- POJ-2251-Dungeon Master(BFS 优先队列)
- Dungeon Master(bfs)
- Dungeon Master(BFS)
- (bfs)Dungeon Master
- 为什么模板类与模板成员函数不能分文件写(.h与.cpp)
- 两个综合查询的SQL存储过程!
- HDU 1069 Monkey and Banana 对比优先权的设置和排序问题(解析)
- 【BZOJ 2151】 种树|堆|贪心|链表
- Linux经典书籍推荐
- AYIT606第七周周赛(3维广搜+队列) D - Dungeon Master地下勇士
- Netty - ByteBuf (3)
- SpringMVC中三个映射处理器类
- 分享一下自己ios开发笔记
- 【HNOI2016】大数
- Java中的泛型类
- 在字符串中找出第一个只出现一次的字符
- HDU 1087 Super Jumping!Jumping!Jumping求连续上升子序列的最大和值 (解析)
- HARK学习(七)--ConstantLocalization