题目: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. C# CRC32

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  2. google map 点击获取经纬度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 修正 phpcmsv9 VIP过期日期为1970

    打开 phpcms/modules/member/member.php 找到 $form_overdudate = form::date('info[overduedate]', date('Y-m- ...

  4. PyQt4学习笔记2:事件和信号

    事件是任何 GUI 程序中很重要的部分.所有 GUI 应用都是事件驱动的.一个应用对其生命期产生的不同的事件类型做出反应.事件是主要由应用的用户产生.但是,也可以通过其他方法产生,比如,网络通信,窗口 ...

  5. 1. Linux驱动开发之开篇--Makefile

    基本Makefile假设现在有3个文件,file2.h是函数声明,file2.c是函数定义,文件file1.c调用file2.c中的函数.则Makefile文件的编写如下: helloworld:fi ...

  6. OFBiz进阶之HelloWorld(二)创建热部署模块

    参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...

  7. RAC环境下SCAN IP可以PING通,1521端口也可以TELNET,但是无法建立数据库连接

    昨天用户请求帮助处理一个问题:有个厂家需要连某个业务系统的数据库,网络上已经开通了权限,SCAN IP可以PING通,测试TELNET 1521端口也是正常.但是想通过SQLPLUS连接,总是会提示连 ...

  8. iOS 通览(一) - 技巧、特性及规范

    一.编译器特性 1.ARC. ARC是编译器特性.项目中使用了ARC,编译器会在项目编译的时候自动添加OC对象计数器release代码.并且使用了ARC,项目中将不允许出现release.retain ...

  9. Integer自动装箱分析

    先看看下面的代码会输出什么: public static void main(String[] args) { Integer i = 127; Integer j = 128; Integer ii ...

  10. 开发之前的思考-UI结构设计

    UI结构设计遵循的一些要点 1.尽量不要让UI作为Camera的子物体 因为UI和摄像机敏感的关系,尽量不要将UI作为摄像机的子物体,避免出现一些因为透视(3D UI)等问题导致的视觉Bug. 2.尽 ...