题目大意:

地牢大师(感觉像是一款游戏啊.......)

    你被困在一个3D的地牢里面,并且需要发现最快的出去的路,这个地牢由很多小立方体组成,有的是空的可以走,有的被岩石填充了不可以走,移动一下要花费1分钟的时间(可以向前后左右上下移动),不能对角移动和移动到迷宫外面,因为迷宫四周都是有岩石包围的。
这是一个逃亡的问题,你需要花费多长时间呢?
//////////////////////////////////////////////////////
简直就是广搜的模板题......直接上吧,1A不错不错
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; #define maxn 100 struct node
{
    int x, y, z, step;
}; int h, m, n;//高,长和宽
//6个方向可以走
int dir[][] = { {,,},{-,,},{,,},{,-,},{,,},{,,-} };
char G[maxn][maxn][maxn]; int OK(int z, int x, int y)//判断这点是否可以走
{
    if(z>=&&z<h && x>=&&x<m && y>=&&y<n && G[z][x][y] != '#')
        return ;
    return ;
}
int DFS(node s, node e)
{
    queue<node> Q;
    Q.push(s);     while(Q.size())
    {
        s = Q.front();Q.pop();         if(s.x==e.x&&s.y==e.y&&s.z==e.z)
            return s.step;         for(int i=; i<; i++)
        {
            node q = s;
            q.x += dir[i][];
            q.y += dir[i][];
            q.z += dir[i][];
            q.step += ;             if(OK(q.z, q.x, q.y) == )
            {
                G[q.z][q.x][q.y] = '#';
                Q.push(q);
            }
        }
    }     return -;
} int main()
{
    while(scanf("%d%d%d", &h, &m, &n), h+m+n)
    {
        int i, j, k;
        node s, e;         for(i=; i<h; i++)
        for(j=; j<m; j++)
        {
            scanf("%s", G[i][j]);
            for(k=; k<n; k++)
            {
                if(G[i][j][k] == 'S')
                {
                    s.z = i;
                    s.x = j;
                    s.y = k;
                    s.step = ;
                }
                if(G[i][j][k] == 'E')
                {
                    e.z = i;
                    e.x = j;
                    e.y = k;
                }
            }
        }         int ans = DFS(s, e);         if(ans != -)
            printf("Escaped in %d minute(s).\n", ans);
        else
            printf("Trapped!\n");
    }     return ;
}

B - Dungeon Master的更多相关文章

  1. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  2. poj 2251 Dungeon Master

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

  3. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

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

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

  5. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  6. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

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

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

  8. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

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

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

  10. 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. sqlserver触发器如何将一个库中的数据插入到另外一个库中

    需求:实现的功能就是,查询当前表的所有信息,插入到另外一个库中(同一台机器,同一个SqlServer) 解决:insert into dB2.dbo.TB2 select * from db1.dbo ...

  2. 十大算法---Adaboost

    当我们有针对同一数据集有多个不同的分类器模型时,怎样组合它们使预测分类的结果更加准确, 针对这种情况,机器学习通常两种策略. 1 一种是bagging,一种是boosting bagging:随机对样 ...

  3. 神秘链接__proto__是什么鬼

    _proto_实际上是某个实例对象的隐藏属性,而prototype是其构造器函数(或者说‘类’)的原型属性; function Mine() {} var  hi = new Function(), ...

  4. jQuery 源码基本框架

    抽丝剥茧, 7000+ 行的 jQuery 源码基本可以概括为以下的伪代码 (function (window, undefined) { //将 document 封装成 jQuery 对象并缓存 ...

  5. 总结几种C#窗体间通讯的处理方法

    摘要:本文介绍了C#窗体间通讯的几种处理方法,即传值.继承.事件回调,希望对大家有用. http://www.cnblogs.com/jara/p/3439603.html 应用程序开发中,经常需要多 ...

  6. VS2010 release 和 debug 调试区别

    VC下Debug和Release区别 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下又无法进行调试,于是只能采用printf方式逐步 ...

  7. linux c数据库备份第一版

    使用linuxC实现的mysql数据库备份目标:通过alarm信号定时备份数据库备注:目前是第一个版,本身不能定时备份可以结合linux自动化实现定时备份.运行平台:Linux或类unix测试平台:u ...

  8. bzoj2180: 最小直径生成树

    Description 输入一个无向图G=(V,E),W(a,b)表示边(a,b)之间的长度,求一棵生成树T,使得T的直径最小.树的直径即树的最长链,即树上距离最远的两点之间路径长度. Input 输 ...

  9. 将Excel导入到数据中

    常用的方式的有两种: 1. 通过 Microsoft.Jet.OLEDB.4.0 或  Microsoft.ACE.OLEDB.12.0 Microsoft.ACE.OLEDB.12.0 需要安装 A ...

  10. ha666_go运行环境配置

    项目地址:http://git.oschina.net/ha666/ha666_go 服务器配置: CPU: 1核 内存: 1024 MB 操作系统: CentOS 7.0 64位 内网IP: 10. ...