//纯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. Linux环境下安装MySQL(解压方式)

    1.将安装包放在服务器上:mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz 2.将安装包解压:tar -zxvf mysql-5.6.37-linux-glibc2 ...

  2. mysql初始化命令及其他命令

    这个问题纠结了我两年: 为了配置my.cnf中 undo的 参数生效,以及生成undo文件,使用一下命令 /usr/bin/mysql_install_db   --defaults-file=/et ...

  3. IPFS中文简介

    ipfs是什么? 它是一个协议也是一个网络,已经运行了2年半,并非虚无缥缈的空气. 它像比特币网络一样,并没有发明什么新技术,他只是将很多种技术(P2P网络技术,bt传输技术,Git版本控制,自证明文 ...

  4. hpuoj 1193: Interval

    Interval [STL.双指针.二分] 题目链接 http://acm.hpu.edu.cn/problem.php?id=1193 或者 题目链接 http://acm.nyist.net/Ju ...

  5. 让Spinner中的文字居中

    如果套用simple_spinner_item或是simple_spinner_dropdown_item,然后直接在Spinner中用 android:gravity="center&qu ...

  6. [SPOJ1557] Can you answer these queries II

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2482 [算法] 线段树维护历史最值 时间复杂度 : O(NlogN) [代码] #i ...

  7. 出现”/var/lib/mysql/mysql.sock“不存在的解决方法

    这种情况大多数是因为你的mysql是使用rpm方式安装的,它会自动寻找 /var/lib/mysql/mysql.sock 这个文件,通过unix socket登录mysql.常见解决办法如下:1.创 ...

  8. poll的使用

    #define POLL_FD_SIZE 1024 int doServicePoll(int listenFd) { struct sockaddr_in cliAddr; socklen_t le ...

  9. 【旧文章搬运】Win7 OBJECT_HEADER之TypeIndex解析

    原文发表于百度空间,2010-08-09========================================================================== 在Wind ...

  10. 抓屏工具 faststone capture

    百度百科 http://baike.baidu.com/link?url=te51CfOKYIEmqT1jsyRwcB8Pnals5xQ8nUXk6trvBPGSJRBO5G7BEZL7cYQxmx8 ...