poj2251:Dungeon Master解题报告
来源:互联网 发布:淘宝购物车打不开 编辑:程序博客网 时间:2024/06/05 10:42
Dungeon Master
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!
Source
Ulm Local 1997
代码:
#include<cstdio>#include<queue>#include<cstring>using namespace std;const int N = 32;char maze[N][N][N];bool vis[N][N][N];int go[][3] = {1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};struct Point{int x,y,z;Point(int xx,int yy,int zz):x(xx),y(yy),z(zz){}};int h,r,c;typedef pair<Point,int> pii;int bfs(int i, int j, int k){memset(vis, 0,sizeof(vis));queue<pii> q;q.push(pii(Point(i,j,k), 0));vis[i][j][k] = true;while(!q.empty()){Point p = q.front().first;int step = q.front().second;if(maze[p.x][p.y][p.z] == 'E') return step;q.pop();for(int i = 0; i < 6; ++i){int nx = p.x + go[i][0];int ny = p.y + go[i][1];int nz = p.z + go[i][2];if(nx >= 0 && nx < h && ny >= 0 && ny < r && nz >= 0 && nz < c && !vis[nx][ny][nz]){if(maze[nx][ny][nz] != '#'){q.push(pii(Point(nx,ny,nz),step + 1));vis[nx][ny][nz] = true;}}}}return -1;}int main(){while(scanf("%d%d%d",&h,&r,&c) && (h||r||c)){for(int i = 0; i < h; ++i){for(int j = 0; j < r; ++j)scanf("%s",maze[i][j]);}int ans;for(int i = 0; i < h; ++i){for(int j = 0; j < r; ++j){for(int k = 0; k < c; ++k)if(maze[i][j][k] == 'S'){ans = bfs(i,j,k);break;}}}if(ans == -1) puts("Trapped!");else printf("Escaped in %d minute(s).\n",ans);}return 0;}
阅读全文
0 0
- poj2251:Dungeon Master解题报告
- POJ2251 Dungeon Master
- POJ2251 Dungeon Master
- poj2251 Dungeon Master (BFS)
- poj2251 - Dungeon Master
- poj2251 Dungeon Master
- POJ2251:Dungeon Master
- Dungeon Master(poj2251,bfs)
- Dungeon Master(poj2251)
- poj2251 Dungeon Master
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master bfs
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master BFS
- poj2251 Dungeon Master
- POJ2251---Dungeon Master
- [bfs]poj2251 Dungeon Master
- django 导入导出
- linux高频命令
- Python3学习(6)--切片【Slice】
- 巧妙地解决缓冲区覆盖问题方法二
- hdu-2063-过山车(匈牙利算法)
- poj2251:Dungeon Master解题报告
- leetcode 654. Maximum Binary Tree
- [经验]【mongodb】查找数据库中存在某一个字段的
- [Hadoop] 传智播客新版Hadoop视频教程 段海涛老师Hadoop八天完全攻克Hadoop视频教程 Hadoop开发
- 【R 语言爬虫】rvest 包实战链家爬虫
- C与C++中const的比较
- 什么是指针?
- C语言树的建立
- 找合法帧