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?

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.

Output

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 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0

Sample Output

Escaped in 11 minute(s).
Trapped!

#include<iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn = 35; int sx,sy,sz,ex,ey,ez,x,y,z;
char cube[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int dir[6][3] = {1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1}; struct Node
{
int x,y,z,t;
Node(int i,int j,int m,int n):x(i),y(j),z(m),t(n){} //构造
Node(){}
}pre; bool judge(int i, int j, int k) //边界
{
if(i < 0 || i >= x ||j < 0 || j >= y || k < 0 || k >= z)
return false;
return true;
} void bfs()
{
memset(vis,0,sizeof(vis));
queue <Node> que;
que.push(Node(sx,sy,sz,0));
vis[sx][sy][sz] = 1;
while(!que.empty())
{
pre = que.front(); que.pop();
if(pre.x == ex && pre.y == ey && pre.z == ez)
{
printf("Escaped in %d minute(s).\n", pre.t);
return ;
}
for(int i = 0; i < 6; i++)
{
int xx = pre.x + dir[i][0];
int yy = pre.y + dir[i][1];
int zz = pre.z + dir[i][2];
if(!vis[xx][yy][zz] && judge(xx,yy,zz) && cube[xx][yy][zz] != '#')
{
vis[xx][yy][zz] = 1;
que.push(Node(xx,yy,zz,pre.t+1));
}
}
}
printf("Trapped!\n");
} int main()
{
while(scanf("%d %d %d", &x, &y, &z) != EOF)
{
if(!x && !y && !z) break;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
scanf("%s", cube[i][j]);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
for(int k = 0; k < z; k++)
if(cube[i][j][k] == 'S')
sx = i,sy = j,sz = k;
else if(cube[i][j][k] == 'E')
ex = i,ey = j,ez = k;
bfs();
}
return 0;
}

【搜索】Dungeon Master的更多相关文章

  1. kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251

    题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...

  2. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  3. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

  4. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  5. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  6. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  7. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  8. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  9. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  10. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. dubbo 实战

    dubbo 官网:http://dubbo.apache.org/zh-cn/docs/user/quick-start.html dubbo-admin 下载 : https://github.co ...

  2. 【Scheme】树结构

    将表作为序列的表示方式,可以推广到元素本身也是序列的序列.例如,我们可以认为对象((1 2) 3 4)是通过(cons (list 1 2) (list 3 4))构造出来的. 这个表包含三个项,其中 ...

  3. python基础入门学习简单程序练习

    1.简单的乘法程序 i = 256*256 print('The value of i is', i) 运行结果: The value of i is 65536 2.执行python脚本的两种方式 ...

  4. 优化-最小化损失函数的三种主要方法:梯度下降(BGD)、随机梯度下降(SGD)、mini-batch SGD

    优化函数 损失函数 BGD 我们平时说的梯度现将也叫做最速梯度下降,也叫做批量梯度下降(Batch Gradient Descent). 对目标(损失)函数求导 沿导数相反方向移动参数 在梯度下降中, ...

  5. 15. 3Sum (重新分配数组大小)

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  6. roof

    roof - 必应词典 美[ruf]英[ruːf] n.屋顶:车顶:顶部:有…顶的 v.给…盖顶:盖上屋顶 网络房顶:楼顶:屋脊 变形复数:roofs:过去分词:roofed:现在分词:roofing ...

  7. 【linux命令总结】——后续用到的内容持续补充和更新

    比如说:某个文件是go文件,名字叫做 Hello.go 1.通过后台运行某个程序,将结果输出到某个文件, 如果是直接运行go程序:go run Hello.go 后台运行:nohup go run H ...

  8. 小服务程序(Java Servlet)

    一般来说,servlet说起来挺高大上的,但是其实实际就是一个能够交互地浏览和修改页面数据,生成一个动态的Web页面. Servlet方法,页面实施请求数据,后台服务器给出响应,将数据返回到页面中去. ...

  9. echarts折线图Demo

    echarts链接:http://echarts.baidu.com/examples/editor.html?c=line-stack 黑底代码:http://gallery.echartsjs.c ...

  10. Inno Setup自定义安装界面脚本

    ; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "RemoteCard&quo ...