链接:

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. vmware克隆linux网络配置

    一.配置Linux网络 在安装Linux的时候,一定要保证你的物理网络的IP是手动设置的,要不然会在Linux设置IP连通网络的时候会报network is unreachable 并且怎么也找不到问 ...

  2. erlang的一些系统限制修改

    atom个数限制 +t xxx 进程数限制 +P xxxx ets表个数限制 +e xxx ports个数限制 +Q xxxx 查看限制 string:tokens(binary_to_list(er ...

  3. Android TextView(EditView)文字底部或者中间 加横线

    Android TextView(EditView)文字底部或者中间 加横线 tv = (TextView) this .findViewById(R.id. text_view ); 中间加横线 t ...

  4. Microsoft SQL Server on Linux破解 2G内存限制

    首先,贴上微软官方安装方法,大家按照官方的操作就行. 微软官方安装方法 相信很多同学遇到一个问题就是: sqlservr: This program requires a machine with a ...

  5. 好久不见(致win7)

    7月8号,电脑上装了pgp,然后说让重启,重启之后蓝屏,自此,就一直蓝屏了 电脑装了双系统,工作时用centos,我不愿重装系统,怕centos受影响 网上说安装模式下可以卸载软件,可我在安全模式下, ...

  6. Thymeleaf系列五 迭代,if,switch语法

      1. 概述 这里介绍thymeleaf的编程语法,本节主要包括如下内容 迭代语法:th:each; iteration status 条件语法:th:if; th:unless switch语法: ...

  7. 20165233 Java第二、三章学习总结

    2017-2018-2 <Java程序设计>第二周学习总结 教材学习内容总结 第二.三章 ch2 标识符与关键字 基本数据类型: 逻辑类型:boolean 整数类型:int.byte.sh ...

  8. PHP环境 PDOException PDOException: could not find driver

    PDOException PDOException: could not find driver in dbcon.php:29 修改php.ini文件中的相关内容.对于找不到php.ini证明你的p ...

  9. delphi IDE插件 cnpack 使用记录

    CnPack  http://www.cnpack.org Alt+F11 ,添加引用,但是文件列表太多,速度慢,打开添加引用窗口后,工具栏有个hook,去掉hook就用IDE自带的速度很快! GE  ...

  10. Cascade属性的取值

    Cascade属性的取值有:1.none:忽略其他关联的对象,默认值.2.save-update:当session通过save(),update(),saveOrUpdate()方法来保存或更新对象时 ...