Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 48380   Accepted: 18252

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!

Source

跟平常的bfs问题的区别就是方向有6个

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define max_v 35
using namespace std;
int dir[][]={{,,},{,,},{,,-},{,-,},{,,},{-,,}};//6个方向 东,南,西,北,上,下
char G[max_v][max_v][max_v];
int vis[max_v][max_v][max_v];
int sx,sy,sz,fx,fy,fz;
int n,m,k;
int ans;
struct node
{
int x,y,z;
int step;
};
bool check(node a)//检查该点合法性
{
if(a.x<||a.x>=n||a.y<||a.y>=m||a.z<||a.z>=k)
return false;
else if(G[a.z][a.x][a.y]=='#')
return false;
else if(vis[a.z][a.x][a.y])
return false;
else
return true;
}
void bfs(int x,int y,int z)
{
queue<node> q;
node p,next; p.x=x;
p.y=y;
p.z=z;
p.step=; q.push(p); while(!q.empty())
{
p=q.front();
q.pop(); if(p.x==fx&&p.y==fy&&p.z==fz)
{
ans=p.step;
return ;
} for(int i=;i<;i++)
{
next.x=p.x+dir[i][];
next.y=p.y+dir[i][];
next.z=p.z+dir[i][]; if(check(next))
{
vis[next.z][next.x][next.y]=;
next.step=p.step+;
q.push(next);
} }
}
}
int main()
{
while(~scanf("%d %d %d",&k,&n,&m))
{
if(n==&&m==&&k==)
break; for(int z=;z<k;z++)
{
for(int i=;i<n;i++)
{
scanf("%s",G[z][i]);
for(int j=;j<m;j++)
{
if(G[z][i][j]=='S')
sx=i,sy=j,sz=z;
else if(G[z][i][j]=='E')
fx=i,fy=j,fz=z;
}
}
} memset(vis,,sizeof(vis));
ans=-; bfs(sx,sy,sz); if(ans==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
}
return ;
}

POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)的更多相关文章

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

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

  2. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  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. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  5. BFS POJ 2251 Dungeon Master

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

  6. poj 2251 Dungeon Master

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

  7. POJ 2251 Dungeon Master (三维BFS)

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

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

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

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. css/jq--弹窗写法介绍,jq插件介绍

    //html文件 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  2. 百度 echarts K线图使用

    看个效果图先 首先在需要插入图例的HTML中嵌入 <div id="main" style="height:400px"></div> ...

  3. 5分钟搞定jQuery+zepto.js+面向对象插件

    今天分享一下快速使用jQuery+zepto.js的技巧,需要的记得收藏 1.jQuery的引入:本地下载jQuery(后面简称jq)的源文件,开发版本使用非min版,线上使用min版,zepto.j ...

  4. opencv3.2.0实现读取多张图片的方法(利用sprintf()函数)

    简介: 将连续的图片转换成视频时,首先需要把图片全部读入,然后再做相应处理,该程序利用sprintf()函数,实现连续图片的读入 /*********新建QT控制台程序,实现多张连续图片的读取**** ...

  5. FFmpeg精确时间截取视频

    简介: 之前用到过FFmpeg截取过音频和视频发现,截取的视频文件时间不是很准确,今天便系统的学习了一下FFmpeg截取视频的知识 参考: https://zhuanlan.zhihu.com/p/2 ...

  6. CentOS7系列--2.1CentOS7中安装配置NTP服务

    CentOS7安装配置NTP服务 NTP服务是时间同步服务 1. 安装NTPd [root@centos7 ~]# yum install -y ntp [jack@centos7 ~]$ vi /e ...

  7. 管理DnS服务器知识点

    DNS服务器是计算机域名系统 (Domain Name System 或Domain Name Service) 的缩写,它是由域名解析器和域名服务器组成的.域名服务器是指保存有该网络中所有主机的域名 ...

  8. linux 软件包安装方式选择、安装位置、源码包安装

    对外提供服务,比如apache,应使用源码包安装对内提供服务,比如gcc,只是我自己使用,使用rpm包安装 rpm包不需要指定安装位置,源码包的安装需要手动指定安装位置 rpm包默认安装位置/etc/ ...

  9. oracle 手动打jar 包

    1.到loracle 的安装目录,D:\ProgramFiles\oracle\product\11.2.0\dbhome_1\jdbc\lib,找到文件 ojdbc6.jar,复制到 D 盘. 2. ...

  10. iostat 工具分析I/O性能

    iostat命令用途:主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的次数和 ...