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: ...
随机推荐
- Sql Server 2016 创建内存数据库
官方教程:https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/survey-of-initial-area ...
- Mall电商项目总结(一)——项目概述
项目概述 此电商项目为本人学习项目,后端 使用nginx实现负载均衡转发请求到多台tomcat服务器,使用多台 redis服务器分布式 缓存用户登录信息. 项目已经部署到阿里云服务器,从阿里云linu ...
- 灵活使用rewrite
Nginx提供的全局变量或自己设置的变量,结合正则表达式和标志位实现url重写以及重定向.rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外 ...
- ansible 文件模块,很实用
摘自: http://blog.csdn.net/kellyseeme/article/details/50545521
- linux从用户组中删除某用户
1. 从wheel组中删除 test用户 gpasswd wheel -d test 2. 给 目录赋予 其他组上传文件的权限 chmod a+w test
- MYSQL进阶学习笔记十三:MySQL 内存优化!(视频序号:进阶_31)
知识点十四:MySQL 内存的优化(31) 一.优化MySQL SERVER 7组后台进程: masterthread:主要负责将脏缓存页刷新到数据文件,执行purge操作,触发检查点,合并插入缓冲区 ...
- IPFS中文简介
ipfs是什么? 它是一个协议也是一个网络,已经运行了2年半,并非虚无缥缈的空气. 它像比特币网络一样,并没有发明什么新技术,他只是将很多种技术(P2P网络技术,bt传输技术,Git版本控制,自证明文 ...
- UVA-11374(最短路)
题意: 机场快线有经济线和商业线,现在分别给出经济线和商业线的的路线,现在只能坐一站商业线,其他坐经济线,问从起点到终点的最短用时是多少,还有路线是怎样的; 思路: 预处理出起点到所有站的最短距离和终 ...
- all.css
@charset "utf-8"*{-webkit-tap-highlight-color:rgba(0,0,0,0); padding:0; margin:0;}body{ fo ...
- 检测SSL证书很好用的三个网站
https://cryptoreport.websecurity.symantec.com/checker/views/certCheck.jsp https://cipherli.st/ https ...