题目:http://poj.org/problem?id=2251

简单三维 bfs不解释, 1A,     上代码

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; int a,b,c;
int vis[][][],G[][][];
int dx[]={,,,,-,};
int dy[]={,,,-,,};
int dz[]={,-,,,,};
struct node
{
int l,r,c,step;
}e,s,pos,next;
int bfs(int l,int r,int c)
{
int i;
queue<node>q;
next.l=l; next.r=r; next.c=c; next.step=;
vis[l][r][c]=;
q.push(next);
while(!q.empty())
{
pos=q.front();
q.pop();
for(i=; i<; i++)
{
next.l=pos.l+dx[i]; next.r=pos.r+dy[i];
next.c=pos.c+dz[i]; next.step=pos.step+;
if(!vis[next.l][next.r][next.c]&&G[next.l][next.r][next.c])
{
vis[next.l][next.r][next.c]=;
q.push(next);
}
if(next.l==s.l&&next.r==s.r&&next.c==s.c)
return next.step;
}
}
return -;
}
int main()
{
int i,j,k,x;
char ch;
while(cin>>a>>b>>c&&(a!=||b!=||c!=))
{
memset(G,,sizeof(G));
memset(vis,,sizeof(vis));
for(i=; i<=a; i++)
for(j=; j<=b; j++)
for(k=; k<=c; k++)
{
cin>>ch;
if(ch=='.')
G[i][j][k]=;
if(ch=='E')
{
e.l=i; e.r=j; e.c=k;
G[i][j][k]=;
}
if(ch=='S')
{
s.l=i; s.r=j; s.c=k;
G[i][j][k]=;
}
}
x=bfs(e.l,e.r,e.c);
if(x==-)
cout<<"Trapped!"<<endl;
else
printf("Escaped in %d minute(s).\n",x);
}
return ;
}

poj 2251 Dungeon Master( bfs )的更多相关文章

  1. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

  2. poj 2251 Dungeon Master (BFS 三维)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  3. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...

  4. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  5. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  6. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  7. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  8. 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 ...

  9. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. flex 弹性盒子模型一些案例.html

    Flexbox是布局模块,而不是一个简单的属性,它包含父元素和子元素的属性. Flex元素是可以让你的布局根据浏览器的大小变化进行自动伸缩. 自适应导航 <ul class="navi ...

  2. Linux文件目录结构说明

  3. 淘宝的ip地址库

    1. 请求接口(GET): http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串] 2. 响应信息: (json格式的)国家 .省(自治区或直辖市 ...

  4. DHT网络第一部分研究结果 加入长期在线的node

    源码:http://jijiea.com/upfile/DHT_Part1_How_To_Join_In_DHT.zip

  5. jsp日期控件My97DatePicker的使用

    My97DatePicker是一款非常灵活好用的日期控件.使用非常简单. 1.下载My97DatePicker组件包 2.将My97DatePicker包放在项目WebContent目录下 3.在页面 ...

  6. GNU_makefile_template

    #g++ compiler: options # -std=c++0x enables ISO C++ 11 standard # -I.. pulls in the Version_test.h f ...

  7. 兼容IE,Firefox,Opera等浏览器的添加到收藏夹js代码实现

    function AddToFavorites() { var title = document.title; var url = location.href; if (window.sidebar) ...

  8. Webx常用接口

    最近在学Webx框架, 在了解webx的工作流程后, 必须要会使用自带的接口和类 常用的 Navigator  这个接口中只有两种类型的方法, 及重定向与转发, 一般用在screen包下的类(注意:s ...

  9. Java注解处理器(转)

    Java中的注解(Annotation)是一个很神奇的东西,特别现在有很多Android库都是使用注解的方式来实现的.一直想详细了解一下其中的原理.很有幸阅读到一篇详细解释编写注解处理器的文章.本文的 ...

  10. 1199: [HNOI2005]汤姆的游戏 - BZOJ

    Description 汤姆是个好动的孩子,今天他突然对圆规和直尺来了兴趣.于是他开始在一张很大很大的白纸上画很多很多的矩形和圆.画着画着,一不小心将他的爆米花弄撒了,于是白纸上就多了好多好多的爆米花 ...