ZOJ 1940 Dungeon Master
来源:互联网 发布:山治两年后的实力知乎 编辑:程序博客网 时间:2024/05/16 19:17
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!
广搜
#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<queue>#include<stack>#include<algorithm>#include<vector>#include<cmath>#include<string>using namespace std;const int maxn=35;int b[maxn][maxn][maxn],f[maxn][maxn][maxn],h,n,m;struct point{int x,y,z,cnt;point(int x=0,int y=0,int z=0,int cnt=0):x(x),y(y),z(z),cnt(cnt){};bool operator ==(const point&a){if (x==a.x&&y==a.y&&z==a.z) return true;return false;}}bg,ed,c[6];point operator+(const point&a,const point&b){return point(a.x+b.x,a.y+b.y,a.z+b.z,a.cnt+b.cnt);}bool check(const point& a){if (a.x<1||a.x>h) return false;if (a.y<1||a.y>n) return false;if (a.z<1||a.z>m) return false;if (b[a.x][a.y][a.z]) return false;if (f[a.x][a.y][a.z]>=0) return false;f[a.x][a.y][a.z]=a.cnt;return true;}string s;int bfs(point &x){int ans=0;memset(f,-1,sizeof(f));f[x.x][x.y][x.z]=0;queue<point> p;p.push(x);while (!p.empty()){point q=p.front();p.pop();if (q==ed) {ans=q.cnt; break;}for (int i=0;i<6;i++)if (check(q+c[i])) p.push(q+c[i]);}return ans;}int main(){c[0]=point(1,0,0,1);c[1]=point(-1,0,0,1);c[2]=point(0,1,0,1);c[3]=point(0,-1,0,1);c[4]=point(0,0,1,1);c[5]=point(0,0,-1,1);while (cin>>h>>n>>m,h+n+m){for (int i=1;i<=h;i++)for (int j=1;j<=n;j++){cin>>s;for (int k=1;k<=m;k++){if (s[k-1]=='#') b[i][j][k]=1;else b[i][j][k]=0;if (s[k-1]=='S') bg=point(i,j,k);if (s[k-1]=='E') ed=point(i,j,k);}}int ans=bfs(bg);if (ans>0) printf("Escaped in %d minute(s).\n",ans);else printf("Trapped!\n");}return 0;}
0 0
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- zoj 1940 Dungeon Master
- zoj - 1940 - Dungeon Master
- zoj 1940 Dungeon Master
- zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master 【BFS】
- zoj 1940 Dungeon Master(BFS)
- ZOJ 1940 Dungeon Master bfs
- zoj 1940 || poj 2251 Dungeon Master
- ZOJ Problem Set - 1940 Dungeon Master
- zoj 1940 || poj 2251 Dungeon Master(bfs)
- NYOJ 353 3D dungeon + zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master (三维广搜)
- ZOJ 1003 Crashing Balloon
- Navicat Premium11.0.16 for mac 破解
- boost之variant使用
- JavaScript匿名函数与闭包
- 排序算法之归并排序
- ZOJ 1940 Dungeon Master
- AYIT暑假集训大二第一周周六赛 B - 汉字统计
- Html 5知识总结
- 动态规划:从新手到专家(当然不可能看完就成专家)(转载)
- DirectX11 创建输入布局
- AFNetworking 的导入(一)
- 浅谈java main()
- POJ 2350Above Average
- CEF Xilium.CefGlue 在当前窗口中打开所有链接(防止弹窗)