UVA - 532 Dungeon Master
来源:互联网 发布:屏幕颜色校正软件 编辑:程序博客网 时间:2024/05/17 08:07
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 Specification
The input file consists of a number of dungeons. Each dungeon description starts with a line containing three integersL, 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 forL, R and C.
Output Specification
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 0Sample Output
Escaped in 11 minute(s).Trapped!该题也是bfs,只是由二维的变为三维;做法几乎一样;#include <cstdio>#include <iostream>#include <queue>#include <cstring>#include <algorithm>using namespace std;const int INF = 1000000000;char g[35][35][35];int L,R,C,tmin,sr,sc,st,er,ec,et;int vis[35][35][35];int dir[6][3] = {{0,0,1},{0,0,-1,},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};struct node{int t,r,c,d;node(){d = 0;}};void Bfs(){node a,b;queue<node> q;a.t = st;a.r = sr;a.c = sc;vis[a.t][a.r][a.c] = 1;q.push(a);while(!q.empty()){a = q.front();q.pop();for(int i = 0; i < 6; ++i){b.t = a.t + dir[i][0];b.r = a.r + dir[i][1];b.c = a.c + dir[i][2];b.d = a.d + 1;if(b.t >= 0 && b.t < L && b.r >= 0 && b.r < R && b.c >= 0 && b.c < C && !vis[b.t][b.r][b.c] && g[b.t][b.r][b.c] != '#'){if(b.t == et && b.r == er && b.c == ec){ tmin = b.d; return;}q.push(b);vis[b.t][b.r][b.c] = 1;}}}tmin = INF;return;}int main(){while(scanf("%d %d %d",&L,&R,&C) == 3){if(!L && !R && !C) break;memset(vis,0,sizeof(vis));memset(g,0,sizeof(g));for(int t = 0; t < L; ++t){for(int i = 0; i < R; ++i){scanf("%s",g[t][i]);for(int j = 0; j < C; ++j){if(g[t][i][j] == 'S') st = t,sr = i,sc = j;else if(g[t][i][j] == 'E') et = t,er = i,ec = j;}}}Bfs();if(tmin == INF) printf("Trapped!\n");else printf("Escaped in %d minute(s).\n",tmin);}return 0;}
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva-532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVa 532Dungeon Master
- uva 532 - Dungeon Master
- UVA 532 Dungeon Master
- uva 532 - Dungeon Master
- uva 532 Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 Dungeon Master
- UVA 532 - Dungeon Master
- android 问题汇总—以后会不断更新。。。
- 线性表:顺序表实现
- 机房收费系统问题篇(二)
- java之时间转换
- 仔细阅读本文相信本文所述对大家的asp.net程序设计有一定的借鉴价值
- UVA - 532 Dungeon Master
- sql优化
- Qt 如何获得适合图片的最大字体!
- 类似QQ登录账号下拉选择框的一种实现
- 2012浙大
- เว็บบริการแทงบอลออนไลน์คือการเข้าใช้บริการที่ดีที่สุด
- Maven学习笔记(六):生命周期与插件
- 《深入理解Android(卷2)》笔记
- java.util.regex