链接:

http://poj.org/problem?id=2251

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21370   Accepted: 8299

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 <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 35 struct node
{
int x, y, z, step;
}; char Map[N][N][N];
node e;
int L, R, C;
int dir[][]={{,,-},{,,},{,-,},{,,},{-,,},{,,}}; bool Judge(node s)
{
return s.x>= && s.x<L && s.y>= && s.y<R && s.z>= && s.z<C && Map[s.x][s.y][s.z]!='#';
} int BFS(node s)
{
node p;
queue<node>Q;
Q.push(s); while(Q.size())
{
s = Q.front(), Q.pop(); if(s.x==e.x && s.y==e.y && s.z==e.z) return s.step; for(int i=; i<; i++)
{
p.x = s.x + dir[i][];
p.y = s.y + dir[i][];
p.z = s.z + dir[i][];
p.step = s.step + ; if(Judge(p))
{
Q.push(p);
Map[p.x][p.y][p.z] = '#';
}
}
}
return -;
} int main()
{
while(scanf("%d%d%d", &L, &R, &C), L+R+C)
{
node s; memset(Map, , sizeof(Map)); for(int i=; i<L; i++)
for(int j=; j<R; j++)
{
scanf("%s", Map[i][j]);
for(int k=; k<C; k++)
{
if(Map[i][j][k]=='S')
s.x=i, s.y=j, s.z=k, s.step=;
if(Map[i][j][k]=='E')
e.x=i, e.y = j, e.z=k;
}
} int ans = BFS(s); if(ans==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n", ans);
} return ;
}

(广搜)Dungeon Master -- poj -- 2251的更多相关文章

  1. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

  2. Dungeon Master POJ - 2251 (搜索)

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

  3. Dungeon Master POJ - 2251(bfs)

    对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...

  4. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

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

  5. B - Dungeon Master POJ - 2251

    //纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...

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

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

  7. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  8. 广搜+输出路径 POJ 3414 Pots

    POJ 3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13547   Accepted: 5718   ...

  9. POJ 2251 Dungeon Master(广搜,三维,简单)

    题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...

随机推荐

  1. Python 定期检查Build_setting的编译情况

    #!/usr/bin/python #_*_ coding:utf-8 _*_ import time from email.MIMEText import MIMEText from email.M ...

  2. ASI接口

    Asynchronous Serial Interface ,异步串行接口,用于传送码流的一个标准DVB接口. 在目前的DVB-C系统设备的传输接口有两种MPEG2视频码流传输接口标准:异步串行接口A ...

  3. bzoj1811 mea

    Description 考虑一个非递减的整数序列 S1,....Sn+1(Si<=Si+1  1<=i<=n). 序列M1...Mn是定义在序列S的基础上,关系式为 Mi=( Si ...

  4. 汇编_指令_JMP

    JMP指令 JMP是汇编语言中的无条件跳转指令.无条件跳转指令可转到内存中任何程序段.转移地址可在指令中给出,也可以在寄存器中给出,或在储存器中指出. 中文名:无条件跳转指令 外文名:JMP 和调用指 ...

  5. jsp中 RequestDispatcher接口的两种跳转:forward()和include()

    在web程序中,经常是由多个Servlet来完成请求.RequestDispatcher接口就是为了多个Servlet之间的调整而实现的.该接口可以用httpSerbletRequest的getReq ...

  6. Electron 前端页面导入jQuery 出现错误Uncaught ReferenceError: jQuery is not defined

    如下: <script src="../assets/js/jquery-1.10.2.js"></script> 方法1 改为: <script&g ...

  7. [ML] CostFunction [Octave code]

    function J = computeCostMulti(X, y, theta) m = length(y); % number of training examples J = 0; for i ...

  8. --- no python application found, check your startup logs for errors

    --- no python application found, check your startup logs for errors 碰到这个问题,请留意下系统执行的python版本和自己的djan ...

  9. OpenCV Hello World

    ▶ OpenCV 的环境配置与第一个程序 ● 去官网下载安装包 https://opencv.org/releases.html ▶ OpenCL 在Visual Studio 2015 中的配置.注 ...

  10. 9 MySQL--多表查询

    多表查询: http://www.cnblogs.com/linhaifeng/articles/7267596.html 1.多表连接查询 2.符合条件连接查询 3.子查询 一.准备表 #建表 cr ...