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. GreenDao-自定义SQL查询-AndroidStudio

    /** * 功能:员工查询 * 方法参数: * strEmpIdOrEmpName:员工ID 或者 员工名称 * strQueryType:员工查询类型 "0": "员工 ...

  2. java面试题:数据库mysql

    Web后端数据库一般用mysql. 数据库基础 Q:数据库三范式是什么? 第一范式:列不可再分 第二范式:行可以唯一区分,主键约束 第三范式:表的非主属性不能依赖与其他表的非主属性 外键约束 且三大范 ...

  3. 在Plesk安装PHP的Memcached扩展

    默认情况下,Plesk的PHP没有Memcached扩展,需要自己安装. Plesk-without-memcached,在Plesk下安装PHP Memcached扩展 PHP Memcache是​ ...

  4. 统计请求最高的TOP 5

    cat access.log |awk -F "," '{print$14}'|awk -F "\"" '{print$4}'|sort |uniq ...

  5. vue bus 的使用

    简单的状态管理,可以用vue bus vue bus可以实现不同组件间.不同页面间的通信,比如我在A页面出发点击事件,要B页面发生变化,使用方法如下: 全局定义:main.js window.even ...

  6. 第三章 列表(d)选择排序

  7. nohup top -p 22452 -b >>jiu.log &

    解释一下: 1. nohup \$order & 后台执行 2. nohup \$order >>$file & 后台执行,并输入指定文件 3. top -p $num 使 ...

  8. 【工具引入】uiautomatorviewer 查找元素后自动生成代码

    缘起 公司部门调整PC部门和无线部门合并,原本负责主站PC端自动化的同事需要马上上手安卓,IOS自动化.对于初次接触移动端的测试者来说,跨度还是有点大的.加之人员有些变动,不得不搞个工具降低学习成本, ...

  9. Toolbar 工具栏 菜单 标题栏 Menu

    要使用Toolbar,要先将标题栏(ActionBar)关掉: style.xml中:<style name="MainActivityTheme" parent=" ...

  10. 网页请求get方式

    方法都是博客中的大神写的,谢谢各路大神. 方法一:(亲测有效) //Get请求方式 private string RequestGet(string Url) { string PageStr = s ...