poj 2251 Dungeon Mastert题目
来源:互联网 发布:linux echo -e命令用法 编辑:程序博客网 时间:2024/06/07 15:15
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 21535 Accepted: 8363
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!
题目大意 有一个多层的迷宫,给你起点和终点,和每一层的结构图,问你最少走多少步可以走出去。
思路 别多想什么直接BFS
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<queue>#include<algorithm>using namespace std;#define inf 0xffffff#define maxn 31int dis[6][3] = {0,0,1, 0,1,0, 1,0,0, 0,0,-1, 0,-1,0, -1,0,0};bool Map[maxn][maxn][maxn];int Map1[maxn][maxn][maxn];struct Node{ int a,b,c;};int s,n,m;char c;queue<Node> Q;Node x,E;bool asd(Node a){ if(a.a < s && a.a >= 0 && a.b < n && a.b >= 0 && a.c < m && a.c >= 0) return true; return false;}int fun(){ while(!Q.empty()) { x = Q.front(); Q.pop(); for(int i = 0; i < 6; i++) { Node e; e.a = x.a + dis[i][0]; e.b = x.b + dis[i][1]; e.c = x.c + dis[i][2]; if(asd(e)) { //cout<<e.a<<" "<<e.b<<" "<<e.c<<endl; if(Map[e.a][e.b][e.c] && !Map1[e.a][e.b][e.c]) { Map1[e.a][e.b][e.c] = Map1[x.a][x.b][x.c] + 1; Q.push(e); } } } }/* for(int i = 0; i < s;i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < m; k++) cout<<Map1[i][j][j]; cout<<endl; } cout<<endl<<endl; }*/ return Map1[E.a][E.b][E.c];}int main(){ while(~scanf("%d%d%d",&s,&n,&m) && s) { getchar(); for(int i = 0; i < s; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < m; k++) { Map1[i][j][k] = 0; scanf("%c",&c); if(c == '#') { Map[i][j][k] = 0; } else { Map[i][j][k] = 1; if(c == 'S') { x.a = i; x.b = j; x.c = k; Q.push(x); } else if(c == 'E') { E.a = i; E.b = j; E.c = k; } } } getchar(); } getchar(); } int ans = fun(); if(ans == 0) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); } return 0;}
0 0
- poj 2251 Dungeon Mastert题目
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- Poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- POJ 2251Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 - Dungeon Master
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- MongoDB整合Spring 详细讲解(含代码)
- Xutils 框架
- 分治排序
- Unity AssetBundle资源打包,Depend依赖关系
- poj3913 Gnome Sequencing
- poj 2251 Dungeon Mastert题目
- Linux-Ubuntu 和 安装 genymotion 的一些问题和一些命令
- 【codevs1557】 热浪, Dijkstra算法入门
- 通过调用沙盒文件动态获取第三方字体库
- java提取域名函数
- 区分接口继承和实现继承(Effective C++_34)
- 01背包
- 数据结构(基本运算验证性实践路线)——顺序表
- Android 中使用rawquery方法查询指定数据的一些方法总结