B - Dungeon Master POJ - 2251
//纯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的更多相关文章
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- Dungeon Master POJ - 2251 (搜索)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- 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 ...
- kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
随机推荐
- Linux环境下安装MySQL(yum方式)
1.下载mysql源安装包shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 安装my ...
- qt使用中的一些问题(linux)
ui_xxx.h的问题 工程中(工作空间)中包含的ui_xxx.h文件是系统自动生成的.这个是xxx.ui的创建文件来的,xxx.ui界面上的都是ui_xxx.h在控制的,在项目里是不显示这个头文件的 ...
- [IR课程笔记]概率检索模型
几个符号意义: R:相关文档集 NR:不相关文档集 q:用户查询 dj:文档j 1/0风险情况 PRP(probability ranking principle):概率排序原理,利用概率模型来估计每 ...
- 挂断电话demo
<!-- 结束通话和打电话的权限 --> <uses-permission android:name="android.permission.CALL_PHONE" ...
- Pager-taglib
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %> & ...
- 浅淡!important对CSS的重要性
SS中的!important是一个非常重要的属性,有时候发挥着非常大的作用,52CSS.com这方面的知识并不是非常多,我们看下面的文章,对它作比较感观的了解. 前几天写一些CSS代码的时候又难为我了 ...
- eval函数用法
JavaScript 全局对象 定义和用法 eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 语法 eval(string) 参数 描述 string 必需.要计算的字 ...
- Codeforces Round #363 (Div. 2) C. Vacations —— DP
题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...
- iPhone HTTP获得XML并使用GDataXML解析
1. [代码][C/C++]代码 NSURL *url = [NSURL URLWithString: @"http://www.raywenderlich.com/downloa ...
- bleve搜索引擎是支持基于field搜索的
Query String Query The query language query allows humans to describe complex queries using a simple ...