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: ...
随机推荐
- 对于URL中文和特殊字符的处理方法
1.中文的处理方法 NSString* string1 = @"https://www.cloudsafe.com/文件夹"; NSString* string2 = [strin ...
- socket 学习笔记
#include <sys/socket.h> ---------------------------------------------------------------------- ...
- Uninstall Tool3.5.3
2.卸载所有和MySQL相关的程序,有好几个,注意,一定要删除与MySQL相关的所有的数据,不能用MySQL自带的卸载,我是用Uninstall Tool3.5.3,在卸载程序界面,右键选择与MySQ ...
- charles抓取线上接口数据替换为本地json格式数据
最近要做下拉刷新,无奈测试服务器的测试数据太少,没有足够的数据做下拉刷新,所以用charles抓取了测试服务器的接口,然后在伪造了很多数据返回到我的电脑上,下面来说说使用方法: 第一步: 安装FQ软件 ...
- Codeforces Round #105 (Div. 2) E. Porcelain —— DP(背包问题)
题目链接:http://codeforces.com/problemset/problem/148/E E. Porcelain time limit per test 1 second memory ...
- H264视频通过RTMP直播
http://blog.csdn.net/firehood_/article/details/8783589 前面的文章中提到了通过RTSP(Real Time Streaming Protocol) ...
- WPF Combo box 获取选择的Tag
string str1 = ((ComboBoxItem)this.cboBoxRate1553B.Items[this.cboBoxRate1553B.SelectedIndex]).Tag.ToS ...
- (QACNN)自然语言处理:智能问答 IBM 保险QA QACNN 实现笔记
follow: https://github.com/white127/insuranceQA-cnn-lstm http://www.52nlp.cn/qa%E9%97%AE%E7%AD%94%E7 ...
- Android Dalvik虚拟机
虽然Android平台使用Java来开发应用程序,但Android程序却不是运行在标准Java虚拟机上的. 可能是出于效率和版权的考虑,Google为Android专门设计了一套虚拟机Dalvik V ...
- UVa 753 A Plug for UNIX (最大流)
题意:给定 n 种插座,m种设备,和k个转换器,问你最少有几台设备不能匹配. 析:一个很裸的网络流,直接上模板就行,建立一个源点s和汇点t,源点和每个设备连一条边,每个插座和汇点连一条边,然后再连转换 ...