三维BFS Poj 2251
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iomanip> using namespace std;
#define maxn 205 int d[][]={{,,},{-,,},{,,},{,-,},{,,},{,,-}};
typedef struct point
{
int x,y,z;
int ans;
}point; point p[maxn];
int Map[][][];
bool used[maxn][maxn][maxn]; int x1,x2,y2,z1,z2;
int you;//这里原本是想用y1的,但是在cmath这个函数中y1(y0,yn等)有自己的定义,发生了冲突(如果将cmath删掉,就可以定义了)
int BFS(int l,int n,int m)
{
int ii,jj,zz;
int i;
queue<point>q;
point temp1,temp2;
temp1.x=x1;
temp1.y=you;
temp1.z=z1;
temp1.ans=;
q.push(temp1);
memset(used, false, sizeof(used));
used[z1][x1][you]=true;
while(!q.empty()){
temp1=q.front();
q.pop();
for(i=;i<;i++)
{
ii=temp1.x+d[i][];
jj=temp1.y+d[i][];
zz=temp1.z+d[i][];
if(ii==x2 && jj==y2 && zz==z2)
{
return temp1.ans+;
}
if(zz>= && zz<l && ii>= && ii<n && jj>= && jj<m && Map[zz][ii][jj]== && used[zz][ii][jj]==false)
{
used[zz][ii][jj]=true;
temp2.x=ii;
temp2.y=jj;
temp2.z=zz;
temp2.ans=temp1.ans+;
q.push(temp2);
}
}
}
return -;
}
int main()
{
int l,m,n,i,j,k,key;
char str[];
while(cin>>l>>n>>m){
if(l==&&n==&&m==){
break;
}
memset(Map, , sizeof(Map));
for(k=;k<l;k++){
for(i=;i<n;i++){
scanf("%s",str);
for(j=;j<m;j++){
if(str[j]=='#')
Map[k][i][j]=;
else if(str[j]=='.')
{
Map[k][i][j]=;
}
else if(str[j]=='S')
{
z1=k;
x1=i;
you=j;
}
else
{
z2=k;
x2=i;
y2=j;
}
}
}
}
key=BFS(l,n,m);
if(key==-)
cout<<"Trapped!"<<endl;
else
printf("Escaped in %d minute(s).\n",key);
}
return ;
}
三维BFS Poj 2251的更多相关文章
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- 【BFS】POJ 2251
POJ 2251 Dungeon Master 题意:有一个地图,三维,走的方向是上下,左右,前后.问你最小步数从起始点走到出口. 思路:三维的BFS,就是多加一组状态,需要细心(不细心如我就找了半个 ...
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
- 【POJ 2251】Dungeon Master(bfs)
BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...
- POJ 2049— Finding Nemo(三维BFS)10/200
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)
POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...
随机推荐
- 对私有API提交的注意事项
1.这个等于堵死了调试断点.关闭就不能断点调试了. 2.对于敏感的函数名要做一个对称加密处理. 防止二进制文件的静态扫描. 3.对于调用私有函数的方法,可以做一个宏定义包装. #define 你的正常 ...
- LVS集群的负载调度
LVS集群的负载调度 章文嵩 (wensong@linux-vs.org) 转自LVS官方资料 2002 年 5 月 本文主要讲述了LVS集群的IP负载均衡软件IPVS在内核中实现的各种连接调度算法. ...
- LwIP移植uCos+stm32f407
LwIP同操作系统一起工作的时候模型如下: 1.TCP/IP协议栈和应用程序以分离的任务运行 2.应用同协议栈沟通是通过API函数调用(API函数调用事实上就是通过OS自带的进程间通信机制,由应用程序 ...
- 重新认识vue之事件阻止冒泡
冒泡的表现 近期用vue做了一个需求,大概是同一个区域,点击不同位置有不同的响应函数,还有个总的响应函数,好吧,如下图所示: 他们的DOM结构如下: <div v-for="(item ...
- this.triggerEvent()用法
在对组件进行封装时 在当前页面想要获取组件中的某一状态,需要使用到this.triggerEvent(' ',{},{}),第一个参数是自定义事件名称,这个名称是在页面调用组件时bind的名称,第二个 ...
- 纯js实现省市级联效果
我们都知道一般有注册的时候会让用户填入省市啊地区什么的,然后我就想使用纯js制作一个省市级联的效果,只是用于学习以及回顾温习用,首先看下效果图,界面很丑啊,不要嫌弃! 首先还是先看下我的项目目录吧 很 ...
- Win8风格的WPF按钮
Win8将Windows的风格又进行了一次变革,我还挺喜欢的,有简洁大气的感觉,华丽绚丽的东西看多了之后总会返璞归真寻找简洁大气的感觉才能心情舒畅. 下面就给个WPF下Button的自定义写法. ...
- Web app root system property already set to different value: 'webapp.root'
java.lang.IllegalStateException: Web app root system property already set to different value: 'webap ...
- 使用geolocation
The geolocation object geolocation API建立在navigator.geolocation 上. 如果对象存在,才可以使用定位服务. if ("geoloc ...
- codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)
题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...