三维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 ...
随机推荐
- 最全的Android源码目录结构详解【转】
本文转载自:http://blog.csdn.net/yangwen123/article/details/8055025 Android 2.1|-- Makefile|-- bionic ...
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...
- Redis缓存服务搭建及实现数据读写 - Eric.Chen
发现博客园中好多大牛在介绍自己的开源项目是很少用到缓存,比如Memcached.Redis.mongodb等,今天得空抽时间把Redis缓存研究了一下,写下来总结一下,跟大家一起分享 一下.由于小弟水 ...
- ping请求超时的解决方法
我们有时需要进行远程或者共享对方数据库的时候,会ping一下对方电脑,时候能够ping通,时候能够进行数据的传输.有时会出现ping请求超时,那么遇到这个问题该怎么解决? 我们首要解决的是看他自己是否 ...
- PICT实现组合测试用例
成功安装后,在命令行中输入命令pict: 可以看到pict命令的一些选项: /o:N 组合数,默认值为2,即pict生成的测试用例集中每条测试数据会有两个值与其他测试集是不同的: /d:C 值 ...
- FFmpeg音视频编解码实践总结
PS:由于目前开发RTSP服务器传输模块时用到了h264文件,所以攻了一段时间去实现h264的视频编解码,借用FFmpeg SDK实现了任意文件格式之间的转换,并实现了流媒体实时播放,目前音视频同步需 ...
- PGTM通用性能测试模型
PTGM通用性能测试模型 一. 测试前期准备阶段 目标: 1. 保证系统稳定性: 2. 建立合适的测试团队. 活动: 1. 系统基础功能验证 类似于BVT测试,确保被测系统已具备进行性 ...
- 在IAR(EWARM)中移植STM32固件库
一.移植环境说明 (1).win10系统 (2).IAR(EWARM)7.7 (3).STM32标准固件库3.5.0 http://www.st.com/content/st_com/en/produ ...
- 火狐浏览器安装VULTR笔记
1.购买一台vultr服务器, 支持支付宝扫码支付,直接美刀转人民币实时结算:优先选日本的,然后美国的; 购买服务器步骤: Server Location: Tokyo Japan Server Ty ...
- 洛谷 1312 Mayan游戏——暴搜+剪枝
题目:https://www.luogu.org/problemnew/show/P1312 自己写了很久.又T又WA的. 发现对题理解有误.改完后应该只有T了,但还是T的. 自己写了许多剪枝,很鸡肋 ...