//纯bfs
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue> using namespace std;
const int maxn = ;
char g[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
int f[][] = { { , , }, { -, , }, { , , }, { , -, }, { , , }, { , , - } };
int L, R, C;
struct node{
int x, y, z;
int flag;
}last, now; void bfs(int x1, int y1, int z1){
vis[z1][x1][y1] = true;
queue<node>q;
while (!q.empty()){
q.pop();
}
last.x = x1; last.y = y1; last.z = z1;
last.flag = ;
q.push(last);
while (!q.empty()){
last = q.front();
q.pop();
if (g[last.z][last.x][last.y] == 'E'){
cout << "Escaped in " << last.flag << " minute(s)." << endl;
return;
}
for (int i = ; i < ; i++){
now.z = last.z + f[i][];
now.x = last.x + f[i][];
now.y = last.y + f[i][];
now.flag = last.flag + ;
if (now.z < || now.z >= L || now.x < || now.y < || now.x >= R || now.y >= C)
continue;
if (!vis[now.z][now.x][now.y] && g[now.z][now.x][now.y] != '#'){
vis[now.z][now.x][now.y] = true;
q.push(now);
}
}
}
cout << "Trapped!" << endl;
} int main(){
ios::sync_with_stdio(false);
while (cin>>L>>R>>C){
if (!L && !R && !C)
break;
int x, y, z;
memset(vis, false, sizeof(vis));
for (int i = ; i < L; i++){
for (int j = ; j < R; j++){
for (int k = ; k < C; k++){
char s;
cin >> s;
g[i][j][k] = s;
if (s == 'S'){
z = i; x = j; y = k;
}
}
}
}
bfs(x, y, z); }
return ;
}

B - 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

    链接: http://poj.org/problem?id=2251 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2137 ...

  4. Dungeon Master POJ - 2251(bfs)

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

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

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

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

  7. poj 2251 Dungeon Master

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

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

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

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

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

随机推荐

  1. 前端photoshop 切图神器cutterman

    1. 切图真的是就件很费力的事情,接下有给大家提供一个工具,本人觉得还不错 http://www.cutterman.cn/ 请参考这个网站,安装方法也有,很简单,我就不说了,赶紧点连接去注册帐号吧

  2. 怎样把word直接转换成ppt

  3. java 浮点数

    package precisenumber; //import java.util.*;public class PreciseNumber { public int fore; public int ...

  4. alsa 编程

    ALSA(Advanced Linux Sound Architecture)是由内核驱动,标准的API库和一系列实用程序组成.因为涉及到版权和BUG的问题Linux 2.6内核抛弃了旧的OSS,AL ...

  5. UVA12293 Box Game —— SG博弈

    题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...

  6. JUC类图

    JUC的类图总览.

  7. 动态规划专题(一) HDU1087 最长公共子序列

    Super Jumping! Jumping! Jumping! 首先对于动态规划问题要找出其子问题,如果找的子问题是前n个序列的最长上升子序列,但这样的子问题不好,因为它不具备无后效性,因为它的第n ...

  8. 四、Chrome开发者工具详解(4)-Profiles面板

    摘自: http://www.cnblogs.com/charliechu/p/6003713.html

  9. ImportCommon

    using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using S ...

  10. [poj2186]Popular Cows(targin缩点)

    题意:求其他所有牛都认为其牛的牛的个数. 解题关键:targin算法模板题,缩点形成一棵树,并不一定是棵树,可能含有多个入度为0的点,寻找出度为0的点(缩点之后的点)的个数,如果个数大于0,则无解,否 ...