POJ 2251 Dungeon Master【BFS】
题意:给出一个三维坐标的牢,给出起点st,给出终点en,问能够在多少秒内逃出。
学习的第一题三维的广搜@_@
过程和二维的一样,只是搜索方向可以有6个方向(x,y,z的正半轴,负半轴)
另外这一题的输入的方式还要再多看看--@_@--
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define maxn 55
using namespace std;
int map[maxn][maxn][maxn],vis[maxn][maxn][maxn];
int dir[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
int l,r,c,flag;
char str[10005];
struct node
{
int x,y,z;
int step;
} st,en;
queue<node> q;
void bfs(int x,int y,int z)
{
node now,next;
while(!q.empty()) q.pop();//调用前清空队列
now.x=x;now.y=y;now.z=z;now.step=0;
q.push(now);
vis[x][y][z]=1;
while(!q.empty())
{
now=q.front();q.pop();
for(int i=0;i<6;i++)
{
next.x=now.x+dir[i][0];
next.y=now.y+dir[i][1];
next.z=now.z+dir[i][2];
if(map[next.x][next.y][next.z]&&!vis[next.x][next.y][next.z])
{
vis[next.x][next.y][next.z]=1;
next.step=now.step+1;//步数加1之后再如队列,因为 搞反 这个wa了好几次
q.push(next);
if(next.x==en.x&&next.y==en.y&&next.z==en.z)
{
flag=1;
en.step=next.step;
return;
}
}
}
}
return;
}
int main()
{
char ch;
int i,j,k;
while(scanf("%d %d %d",&l,&r,&c)!=EOF&&l&&r&&c)
{
flag=0;
memset(map,0,sizeof(map));
memset(vis,0,sizeof(vis)); gets(str);
for(i=1;i<=l;i++)
{
for(j=1;j<=r;j++)
{
for(k=1;k<=c;k++)
{
scanf("%c",&ch);
if(ch=='S') {st.x=i;st.y=j;st.z=k;}
if(ch=='E'){en.x=i;en.y=j;en.z=k;}
if(ch!='#') map[i][j][k]=1;//map数组 相当于限定是否出界
}
gets(str);
}
gets(str);
}
bfs(st.x,st.y,st.z);
if(flag) printf("Escaped in %d minute(s).\n",en.step);
else printf("Trapped!\n");
}
}
go---go-----===
POJ 2251 Dungeon Master【BFS】的更多相关文章
- POJ - 2251 Dungeon Master 【BFS】
题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- poj 2251 Dungeon Master(bfs)
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- (简单) POJ 2251 Dungeon Master,BFS。
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
随机推荐
- c# 获取一年中的周/根据一年中的第几周获取该周的开始日期与结束日期
/// <summary> /// 获取一年中的周 /// </summary> /// <param name="dt">日期</par ...
- UVA 11971 - Polygon 数学概率
Polygon John has been given a segment of lenght N, however he n ...
- 时间处理工具类TimeUtil
转自:https://cnblogs.com/ityouknow/p/5662753.html 功能 Date与String之间的互相转换,以及一些特殊格式的时间字符串处理 代码 /** * 类名:T ...
- 关于markdown的使用
首先: https://www.cnblogs.com/jordangong/p/9804777.html 注意:提交博客时需将 Markdown 源码粘贴到编辑器中,且编辑器没有实时预览,可以上传后 ...
- Aspose office (Excel,Word,PPT),PDF 在线预览
前文: 做个备份,拿的是试用版的 Aspose,功能见标题 代码: /// <summary> /// Aspose office (Excel,Word,PPT),PDF 在线预览 // ...
- Android 度量单位
单位 注释 px(像素) 每个像素对应手机上的一个点,在不同设备上1px表示的长度不一定相同 screen size(屏幕尺寸) 指手机对角线的长度,如4.7英寸 resolution(分辨率) 指屏 ...
- (转载)ScratchView
首页 我的管理 客户端 登录注册 首页 安卓组件中心 安卓代码分享 Swift专区 HTML5移动开发 视频中心 小程序 名称: ScratchView 作者: doliangzhe 来源: gith ...
- SpringMVC学习(二)——SpringMVC架构及组件(及其运行原理)-转载
相信大家通过前文的学习,已经对SpringMVC这个框架多少有些理解了.还记得上一篇文章中SpringMVC的处理流程吗? 这个图大致描述了SpringMVC的整个处理流程,这个流程图还是相对来说比 ...
- HDU 3584 Cube 【 三维树状数组 】
题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 #include< ...
- Uncaught TypeError: Cannot read property 'offsetTop' of undefined at VueComponent.handleScroll
mounted() { window.addEventListener("scroll", this.handleScroll); }, beforeDestroy() { win ...