Dungeon Master

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大 int dx[] = {,,-,,,};
int dy[] = {,,,,,-};
int dz[] = {,-,,,,}; char Map[][][];
int vis[][][], L, R, C; struct node
{
int x, y, z;
int time;
}st, ed;
queue<node> q; bool check(int x, int y, int z)
{
if(x >= && x <= L && y >= && y <= R && z >= && z <= C)
return true;
return false;
} int BFS()
{
int x, y, z, t, i;
while(!q.empty())
{
node tmp = q.front();
q.pop();
x = tmp.x;
y = tmp.y;
z = tmp.z;
t = tmp.time;
for(i = ; i < ; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
int nz = z + dz[i];
if(!vis[nx][ny][nz] && Map[nx][ny][nz] != '#' && check(nx,ny,nz))
{
if(nx == ed.x && ny == ed.y && nz == ed.z)
return t+;
vis[nx][ny][nz] = ;
node temp;
temp.x = nx;
temp.y = ny;
temp.z = nz;
temp.time = t + ;
q.push(temp);
}
}
}
return -;
} int main()
{
while(~scanf("%d%d%d",&L, &R, &C) && (L + R + C))
{
memset(vis,,sizeof(vis));
int i, j, k;
for(i = ; i <= L; i++)
{
for(j = ; j <= R; j++)
{
for(k = ; k <= C; k++)
{ cin>>Map[i][j][k];
if(Map[i][j][k] == 'S')
{
st.x = i, st.y = j, st.z = k;st.time = ;
q.push(st);
vis[i][j][k] = ;
}
else if(Map[i][j][k] == 'E')
ed.x = i, ed.y = j, ed.z = k;
}
}
}
int ans = BFS();
if(ans == -)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
while(!q.empty()) q.pop();
}
return ;
}

ZOJ 1940 Dungeon Master 三维BFS的更多相关文章

  1. 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 ...

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

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

  3. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  4. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  5. ZOJ 1940 Dungeon Master【三维BFS】

    <题目链接> 题目大意: 在一个立体迷宫中,问你从起点走到终点的最少步数. 解题分析: 与普通的BFS基本类似,只需要给数组多加一维,并且走的时候多加 上.下这两个方向就行. #inclu ...

  6. Dungeon Master(三维bfs)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  7. UVa532 Dungeon Master 三维迷宫

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

  8. 【POJ - 2251】Dungeon Master (bfs+优先队列)

    Dungeon Master  Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...

  9. 棋盘问题(DFS)& Dungeon Master (BFS)

    1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

随机推荐

  1. 【驱动】USB驱动·入门【转】

    转自:http://www.cnblogs.com/lcw/p/3159371.html Preface USB是目前最流行的系统总线之一.随着计算机周围硬件的不断扩展,各种设备使用不同的总线接口,导 ...

  2. p,br,hn,b,i,u,s,sup,sub标签

    <!--   -->注释 <p></p>段落标签 <br />换行标签 <h1></h1> 字体标签  最大 <h6> ...

  3. NuGet套件还原步骤(以vs2012为例)

    下载别人的范例,出现由于Nuget套件不存在而无法启动时: 效果如下图: 步骤如下: 1.点击 项目->启用NuGet程序包还原 2.点击下图中的是 3.点击下图中的确定 4.效果如图: . 5 ...

  4. 在Eclipse使用Gradle

    1.Gradle安装 1.Grandle官网下载Gradle,地址:http://www.gradle.org/downloads 2.设置环境变量,需要设置如下2个环境变量 2.1添加GRADLE_ ...

  5. 使用Scrapy命令行工具【导出JSON文件】时编码设置

    Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 使用scrapy命令行工具建立了爬虫项目(startproject),并使用s ...

  6. FTRL算法

    稀疏解的作用:内存和时间啊 实际的互联网广告应用需要的是快速地进行model的更新.为了保证快速的更新,训练样本是一条一条地过来的,每来一个样本,model的参数对这个样本进行一次迭代,从而保证了mo ...

  7. html元素分类

    目录 块级元素 内联元素 内联块级元素  总结 一.块级元素(block) 定义:默认情况下,独占一行的元素就是块级元素. 特点: 每个块级元素都从新的一行开始,并且其后的元素也另起一行.(真霸道,一 ...

  8. 两行代码搞定js对象深浅拷贝

    有一段时间没有更新博客了,忙于工作.2018年刚过去,今天来开启2018第一篇博文.好了,咱们步入正题. 先上代码 /** * 遍历对象 * 1.判断是不是原始值 * 2.判断是数组还是对象 * 3. ...

  9. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  10. 【[国家集训队]小Z的袜子】

    对于L,R的询问.设其中颜色为x,y,z的袜子的个数为a,b,c...那么答案即为(a*(a-1)/2+b*(b-1)/2+c*(c-1)/2....)/((R-L+1)*(R-L)/2)化简得:(a ...