题目

简单的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. 《postfix邮件服务下mailq、postmap、postqueue 、 postsuper等用法》

    1.Mailq 功能说明:显示待寄邮件的清单. 语 法:mailq [-q] 补充说明:mailq可列出待寄邮件的清单,包括邮件ID,邮件大小,邮件保存时间,寄信人,收信人,以及邮件无法寄出的原因,提 ...

  2. silverlight Frame嵌套页面刷新问题

    1.此方法将会刷新到主页面 private void btn_Click(object sender, RoutedEventArgs e) { HtmlPage.Window.Eval(" ...

  3. php curl post

    public static function curlPost($url, $data=array()) {        $ch = curl_init();        if (is_array ...

  4. Crusher Django Tutorial(5) 使用内置管理员系统

    http://crusher-milling.blogspot.com/2013/09/crusher-django-tutorial5-using-admin.html 顺便学习一下FQ Crush ...

  5. 有趣的checkbox动画切换状态(支付宝转账成功显示)--第三方开源--AnimCheckBox

    这个很有趣的指标通过AnimCheckBox实现,下载地址:https://github.com/lguipeng/AnimCheckBox 代码: activity_main.xml: <Re ...

  6. 微软更换考试中心后报名攻略以及MCT半价

    微软从Prometric更换为Pearson的考试中心,比起以前的预约流程更加便捷. Pearson VUE为微软公司提供MCP考试服务 Pearson VUE为微软公司提供MCP考试服务 http: ...

  7. MySQL 5.6.26源码安装

    5.6.26源码安装包:http://pan.baidu.com/s/1kUl44WRcmake安装包链接:http://pan.baidu.com/s/1c0LuwJA 操作系统版本:CentOS ...

  8. 通过替换frm文件方式修改表结构

    版本:5.6.16 在自己的虚拟环境中,测试创建一个表,表结构如下:mysql> drop table yoon_temp;Query OK, 0 rows affected (0.09 sec ...

  9. 无法解析的外部符号 _WinMain@16 fatal error LNK1120: 1 个无法解析的外部命令

    一,问题描述MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 ...

  10. hadoop的核心思想

    hadoop的核心思想 1.1.1. hadoop的核心思想 Hadoop包括两大核心,分布式存储系统和分布式计算系统. 1.1.1.1. 分布式存储 为什么数据需要存储在分布式的系统中哪,难道单一的 ...