#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的更多相关文章

  1. BFS POJ 2251 Dungeon Master

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

  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. 【BFS】POJ 2251

    POJ 2251 Dungeon Master 题意:有一个地图,三维,走的方向是上下,左右,前后.问你最小步数从起始点走到出口. 思路:三维的BFS,就是多加一组状态,需要细心(不细心如我就找了半个 ...

  5. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

  6. 【POJ 2251】Dungeon Master(bfs)

    BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...

  7. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

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

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

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

随机推荐

  1. go 包的问题

    同一个包下的所有方法,都整合到一个里面去了,通过包名可以任意调用包下的方法. 文件夹的名字必须要和文件里面的package的名字一样,否则会报错... 导文件就是文件所在的包 导包import(),是 ...

  2. Linux - Unix环境高级编程(第三版) 源代码编译(即头文件apue.h如何使用问题)【转】

    本文转载自:http://blog.csdn.net/hadas_wang/article/details/43203795 1. 下载代码:http://www.apuebook.com/code3 ...

  3. x264 --fullhelp

    >x264 --fullhelp x264 core: Syntax: x264 [options] -o outfile infile Infile can be raw (in which ...

  4. html5--4-1 video/视频播放

    html5--4-1 video/视频播放 学习要点 掌握video元素的基本用法 直到现在,在网页中的大多数视频是通过插件(比如 Flash)来显示的.然而,并非所有浏览器都拥有同样的插件. HTM ...

  5. match_parent 、 fill_parent 、 wrap_content

    1)fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间.这跟Windows控件的dockstyle属性大体一致. 设置一个顶部布局或 ...

  6. CISCO-从路由器上下载IOS

    准备工作:一台装有TFTP服务器的PC,一台带有IOS的路由器,并用网线连接上 设置路由器接口和计算机网卡的IP地址在同一网段,并且互相能ping通. 1,安装Cisco TFTP Server 2, ...

  7. ORA-12547: TNS:lost contact

    碰到这个ORA-12547: TNS:lost contact的问题,翻了很多资料和METALINK,总结了一下原因: 1 是由于rpm包没有安装,对于我们的生产环境,此包是安装的. admin@p1 ...

  8. Mysql数据库的打开和关闭

    Mysql数据库的打开和关闭: 选择计算机(win7)-右键管理 在新窗口选择--服务 5 找到mysql,然后右键-启动(停止)

  9. 升级后,使用dynamic报错

    程序升级为.NET 4.0后,在程序中使用dynamic时出现下列错误 错误 5 预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入错误 4 找不 ...

  10. tabbar

    1 tabbar不显示的问题: 命名在app.json中配置了tabbar但是不显示可能的问题: app.json中的pages中第一个路径没有在tabbar中设置 原因:app.json中配置的pa ...