题目

简单的3d广搜,做法类似与 hdu 的 胜利大逃亡

#define  _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 32
char map[MAXN][MAXN][MAXN];
int a,b,c;
bool vis[MAXN][MAXN][MAXN];
struct tt
{
int x,y,z,step;
};
queue<tt>q;
int xx[]={,,,-,,};
int yy[]={,-,,,,};
int zz[]={,,,,,-};
int bfs(int sx,int sy,int sz,int ex,int ey,int ez)
{
if(a==&&b==&&c==)return ;
while(!q.empty())
q.pop();
memset(vis,false,sizeof(vis));
tt front,rear,temp;
front.x=sx;front.y=sy;front.z=sz;front.step=;
q.push(front);
vis[sx][sy][sz]=true;
while(!q.empty())
{
temp=q.front();
q.pop();
if(temp.x==ex&&temp.y==ey&&temp.z==ez)
return temp.step;//原来是这个放错地方了,应该对出栈的数据进行检验
for(int i=;i<;i++)
{
rear.x=temp.x+xx[i];
rear.y=temp.y+yy[i];
rear.z=temp.z+zz[i];
rear.step=temp.step+;
if(rear.x>=&&rear.x<a&&rear.y>=&&rear.y<b&&rear.z>=&&rear.z<c&&map[rear.x][rear.y][rear.z]!='#'&&vis[rear.x][rear.y][rear.z]==false)
{
q.push(rear);
vis[rear.x][rear.y][rear.z]=true;
}
}
}
return ;
} int main()
{
int i,j,k,ans,ex,ey,ez,sx,sy,sz;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if(a==&&b==&&c==)break;
for(i=;i<a;i++)
{
for(j=;j<b;j++)
{
scanf("%s",map[i][j]);
for(k=;k<c;k++)
{
if(map[i][j][k]=='S')
sx=i,sy=j,sz=k;
if(map[i][j][k]=='E')
ex=i,ey=j,ez=k;
}
}
}
ans=bfs(sx,sy,sz,ex,ey,ez);
if(ans==)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
}
return ;
}

POJ 2251 Dungeon Master(广搜,三维,简单)的更多相关文章

  1. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

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

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

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

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

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

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

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

  6. BFS POJ 2251 Dungeon Master

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

  7. POJ 2251 Dungeon Master (三维BFS)

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

  8. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  9. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

随机推荐

  1. MySQL Limit order by

    今天写模糊查询的时候,按照时间排序并进行分页时,在mybatis的映射文件中有这样一条sql语句 SELECT <include refid="Base_Column_List&quo ...

  2. ArcGIS10中matplotlib画图时的中文设置

    利用GIS的数据批量生成XY的图形图像文件,可以直接使用Python.一般大家都是用matplotlib,中文设置的问题参看了许多内容,结论是对错不一,让我折腾了三天,现总结如下: 1.软件的版本.安 ...

  3. 1.servlet hello实例---HelloServlet

    1.用url调用servlet 建 web project “HelloServlet”,在src下建包com.amaker.servlet,在包下建HelloServlet.java. packag ...

  4. Android BroadcasetReceiver

    ci@clinux:~/mp_mtk$ adb -s QGAEFYAAOFN7PNOB logcat PhoneReceiver:e *:S --------- beginning of system ...

  5. Java Web动态配置log4j

    导入log4j的jar包, 在web.xml中做如下配置 <!-- Log4j Configuration --> <context-param> <param-name ...

  6. Lucene Field

    org.apache.lucene.demo.IndexFiles类中,使用递归的方式去索引文件.在构造了一个IndexWriter索引器之后,就可以向索引器中添加Doucument了,执行真正地建立 ...

  7. Linux大量TIME_WAIT的解决办法

    发布:theboy   来源:net   [大 中 小] 根据TCP协议定义的3次握手断开连接规定,发起socket主动关闭的一方 socket将进入TIME_WAIT状态,TIME_WAIT状态将持 ...

  8. 如何在ARC代码中混编非ARC代码

    “ios中如果arc和非arc文件混编,可以在build parses中指定compile flags,如果arc文件设为"-fobjc-arc",非arc文件设为"-f ...

  9. python学习第七天

    一.        subprocess 模块 1. subprocess的介绍:用来替代几个老的模块或是函数,如:os.systam,os.popen,os.spawn*,os.popen2*,co ...

  10. 关于字符串 “*****AB**C*D*****” 中前缀、后缀和中间 '*' 的处理

    一.删除前缀 '*' #include<iostream> #include<cstdio> using namespace std; //主函数 int main() { ] ...