Dungeon Master POJ - 2251
走迷宫模板变种
三维BFS
就是二维bfs的判断多写一点,多写一个dz数组
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)ll cnt,n,m,t,ans,ant,l;
const int N=55;
char arr[N][N][N];
ll dist[N][N][N];
ll dx[]={0,0,0,0,1,-1};
ll dy[]={1,-1,0,0,0,0};
ll dz[]={0,0,-1,1,0,0};
string str;
struct Edge
{ll x,y,z;
};
Edge on;
Edge off;inline ll read()
{char c = getchar();int x = 0,s = 1;while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字return x*s;
}ll bfs()
{queue<Edge>q;q.push(on);memset(dist,-1,sizeof dist);dist[on.x][on.y][on.z]=0;while(!q.empty()){Edge tt=q.front();q.pop();repr(i,0,6){ll x=tt.x+dx[i],y=tt.y+dy[i],z=tt.z+dz[i];if(x>=0&&y>=0&&z>=0&&x<m&&y<n&&z<l&&(arr[x][y][z]=='.'||arr[x][y][z]=='E')&&dist[x][y][z]==-1){Edge ttt;ttt.x=x,ttt.y=y,ttt.z=z;dist[x][y][z]=dist[tt.x][tt.y][tt.z]+1;q.push(ttt);}}}return dist[off.x][off.y][off.z];
}void solve()
{repr(i,0,l)repr(j,0,n)repr(k,0,m) {// scanf("%c",&arr[k][j][i]);cin>>arr[k][j][i];if(arr[k][j][i]=='S') on.x=k,on.y=j,on.z=i;if(arr[k][j][i]=='E') off.x=k,off.y=j,off.z=i;}ans=bfs();if(ans==-1) puts("Trapped!");else printf("Escaped in %lld minute(s).\n",ans);return;
}int main()
{while(1){l=read(),n=read(),m=read();if(l==0&&m==0&&n==0) return 0;solve();}return 0;
}
Dungeon Master POJ - 2251相关推荐
- B - Dungeon Master POJ - 2251
B - Dungeon Master POJ - 2251 题目: 逃离3D迷宫,n <=30 首先是dfs,算一下最坏情况共30层,每层有30*30的循环, 复杂度 3030*30 显然严重爆 ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- Dungeon Master POJ - 2251 BFS
一.内容 题意:给定一个3D的图,你能走6个方向,问从起点到终点最少的步数. 二.思路 bfs搜索一下. 三.代码 #include <cstdio> #include <cstri ...
- (POJ - 2251)Dungeon Master(bfs)
题目链接:2251 -- Dungeon Master (poj.org) 这是一个典型的bfs迷宫问题,只不过是三维的,唯一需要注意的就是输入要用cin,不要用scanf,因为有换行,其他没什么了, ...
- POJ 2251 Dungeon Master(三维BFS求最短路径)
3D dungeon 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...
- POJ 2251 - Dungeon Master + Python实现
原题连接:2251 -- Dungeon Master 参考资料:POJ 2251 - Dungeon Master | 眈眈探求 问题:从起点S,经上下左右前后行走,到达目的地E点,返回所经过的路径 ...
- Dungeon Master(poj2251,bfs)
http://poj.org/problem?id=2251 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15203 Dun ...
- 1248:Dungeon Master/P2360 地下城主
1248:Dungeon Master 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 10942 通过数: 4388 [题目描述] 这题是一个三维的迷宫题 ...
- Dungeon Master 地下城大师(BFS进阶)
题目链接:2251 -- Dungeon Master 知道你看不懂题(手动滑稽):友情链接. 题意:找到从S到E的最少步数的路径,输出该步数,不过有意思的是这个类似迷宫问题不是二维的,是一个三维迷宫 ...
最新文章
- ubuntu下使用SVN
- IT项目管理之系统部署
- uva 299 - Train Swapping
- PHP安装swoole扩展
- 【时间序列】使用 Auto-TS 自动化时间序列预测
- python数据结构_(列表)大O性能_学习笔记(2)
- Python画数码晶体管日期(年月日时分秒)
- delphi 2010之如何快速开发原生ActiveX控件
- 最新Windows SDK for Windows7 开发包下载
- aload、aload_1、iload都是什么意思
- 使用计算机传真,使用计算机发送和接收传真
- Power BI——数据建模案例分析
- 细胞色素--训练13
- Vue项目:IE11中地址栏直接改变路由页面不跳转bug
- 2篇SCI二区认定优秀博士!57万安家费+100万房补,浙江高校!
- fast RCN论文笔记
- Google Chrome谷歌浏览器崩溃,错误代码: STATUS_STACK_BUFFER_OVERRUN
- Zhong__CentOS7安装Elasticsearch笔记
- 为什么现在90后员工离职率那么高?
- leetcode 537 py 中map函数用法
热门文章
- 出国开会总结,学生,初次出国参加学术会议
- 李永乐复习全书概率论与数理统计 第三章 多维随机变量及其分布
- Android中RSA加密
- 计算机组成与设计 视频,《计算机组成与设计》计算机组成原理视频教程 清华大学王诚著...
- 生成订单编号,编号格式(由编号类型编码+编号创建平台编码+6位日期+时间戳后4位+4位随机数组成),生成四位或者N位随机数字
- 计算机网络自顶向下方法简答题与综述题题目与答案汇总
- 爬虫爬取学校通知信息(python))
- 大学计算机教程 曾俊,大学计算机基础教程
- Unity游戏开发之绘制准心
- 程序员-开发工作流程英文术语