题目大意:

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

    你被困在一个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. AVAudioSession

    AVAudioSession类由AVFoundation框架引入.每个IOS应用都有一个音频会话.这个会话可以被AVAudioSession类的sharedInstance类方法访问,如下: AVAu ...

  2. JavaScript 计时事件

    JavaScript 计时事件 通过使用 JavaScript,我们有能力作到在一个设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行.我们称之为计时事件. 在 JavaScritp 中使用计 ...

  3. 330. Patching Array--Avota

    问题描述: Given a sorted positive integer array nums and an integer n, add/patch elements to the array s ...

  4. php定时执行任务的几个方法

    PHP的实现决定了它没有Java和.Net这种AppServer的概念, 而http协议是一个无状态的协议, php只能被用户触发, 被调用, 调用后会自动退出内存, 没有常驻内存, 就没有办法准确的 ...

  5. 『重构--改善既有代码的设计』读书笔记----Hide Delegate

    所谓委托关系,就是一个类对于另一个类来说纯粹作为接口转发,即客户通过一个委托类去调用另一个对象.直白的委托关系就是委托类直接返回出目标类给客户调用,这个关系很麻烦,因为委托关系的变动就会影响客户端的代 ...

  6. C#快速导入海量XML数据至SQL Server数据库

    #region 将Xml中的数据读到Dataset中,然后用SqlBulkCopy类把数据copy到目的表中using (XmlTextReader xmlReader = new XmlTextRe ...

  7. Bootstrap_Javascript_滚动监视器

    滚动监控器是Bootstrap提供的非常实用的JavaScript插件,被广泛应用到Web开发中.其表现形式是: 1.当用户鼠标滚动时,滚动条的位置会自动更新导航条中相应的导航项. 2.用户拖动滚动条 ...

  8. centos postfix 邮箱安装记录

    ---恢复内容开始--- #wget http://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.9 ...

  9. 机器学习实验报告:利用3层神经网络对CIFAR-10图像数据库进行分类

    PS:这是6月份时的一个结课项目,当时的想法就是把之前在Coursera ML课上实现过的对手写数字识别的方法迁移过来,但是最后的效果不太好… 2014年 6 月 一.实验概述 实验采用的是CIFAR ...

  10. [151116 记录] 使用Python3.5爬取豆瓣电影Top250

    这一段时间,一直在折腾Python爬虫.已有的文件记录显示,折腾爬虫大概个把月了吧.但是断断续续,一会儿鼓捣python.一会学习sql儿.一会调试OpenCV,结果什么都没学好.前几天,终于耐下心来 ...