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. python基础===一行 Python 代码实现并行(转)

    原文:https://medium.com/building-things-on-the-internet/40e9b2b36148 译文:https://segmentfault.com/a/119 ...

  2. 如何开启mysql5.5的客户端服务 命令行打开方法

    MySQL分为两个部分,服务器端和客户端,只有服务器端的服务开启后,才可以通过客户端登录到MySQL数据库.这里介绍如何用命令行方式开启mysql的客户端服务. 在计算机上安装好mysql软件   我 ...

  3. 比特币pow算法介绍

    Proof Of Work 工作量证明 借鉴了 哈希现金(Hashcash)-1997年 英国密码学专家亚当.贝克(Adam Back) 用工作量证明系统解决了互联网垃圾邮件问题,它要求计算机在获得发 ...

  4. Unity教程之-Unity3d中针对Android Apk的签名验证(C#实现)

    当Unity开发的游戏以Android Apk的形式发布之后,经常会遇到的一种情况就是别人对我们的游戏进行二次打包,也就是用他们的签名替换掉我们的签名,从而堂而皇之的将胜利果实占为己有.面对这样的情况 ...

  5. Python_oldboy_自动化运维之路_全栈考试(七)

    1. 计算100-300之间所有能被3和7整除的所有数之和 # -*- coding: UTF-8 -*- #blog:http://www.cnblogs.com/linux-chenyang/ c ...

  6. supervisor的安装和配置

    1. 安装 yum install supervisor 2.配置 [unix_http_server] file=/tmp/supervisor.sock ;UNIX socket 文件,super ...

  7. HDU 1068 Girls and Boys(最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...

  8. information_schema Introduction

    information_schema介绍 information_schema数据库是MySQL自带的,里面的“表”保存着服务器当前的实时信息.它提供了访问数据库元数据的方式.元数据是关于数据的数据, ...

  9. PostgreSQL数据库如果不存在则插入,存在则更新

    INSERT INTO UM_CUSTOMER(customercode,CompanyFlag,InputTime,LocalVersion) ) ON conflict(customercode) ...

  10. SQL 2008 还原SQL 2005备份文件不成功的解决方

    在SQL Server 2008 r2上还原一个SQL Server 2005时,还原不成功,提示如下信息: 按照如下情况则还原成功: -- 查看备份文件的类型 RESTORE FILELISTONL ...