NYOJ--353--bfs+优先队列--3D dungeon

时间:2021-12-05 16:51:34
/*
    Name: NYOJ--3533D dungeon
    Author: shen_渊
    Date: 15/04/17 15:10
    Description: bfs()+优先队列,队列也能做,需要开一个vis[35][35][35]标记
*/

#include<iostream>
#include<queue>
using namespace std;
struct node{
    int x,y,z,steps;
    node():steps(){
    };
    bool operator <(const node &a)const {
        return steps>a.steps;
    }
};
int bfs();
priority_queue<node> q;
int l,r,c;
node s,e;
][][];
] = {{,,},{-,,},{,,},{,-,},{,,},{,,-}};
int main()
{
//    freopen("in.txt","r",stdin);
    while(cin>>l>>r>>c,l+r+c){
        ; i<l; ++i){
            ; j<r; ++j){
                cin>>map[i][j];
                ; k<c; ++k){
                    if(map[i][j][k] == 'S')s.x = j,s.z = i,s.y = k;
                    if(map[i][j][k] == 'E')e.x = j,e.y = k,e.z = i;
                }
            }
        }
        int t;
        if (t=bfs())
            cout << "Escaped in " << t << " minute(s)." << endl;
        else
            cout << "Trapped!" << endl;
    }
    ;
}
int bfs(){
    while(!q.empty()) q.pop();
    q.push(s);
    while(!q.empty()){
        node temp = q.top();q.pop();
        ; i<; ++i){
            node a = temp;
            a.z += dir[i][];
            a.x += dir[i][];
            a.y += dir[i][];
            a.steps++;
            if(a.z == e.z&& a.x==e.x&&a.y==e.y)return a.steps;
            if(map[a.z][a.x][a.y] == '#')continue;
             || a.z>=l)continue;
             || a.x>=r)continue;
             || a.y>=c)continue;
            q.push(a);
            map[a.z][a.x][a.y] = '#';
        }
    }
    ;
}

NYOJ--353--bfs+优先队列--3D dungeon的更多相关文章

  1. nyoj 353 3D dungeon

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 You are trapped in a 3D dungeon and need to find ...

  2. NYOJ353 3D dungeon 【BFS】

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...

  3. 3D dungeon

    算法:广搜: 描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is comp ...

  4. POJ 1724 ROADS&lpar;BFS&plus;优先队列&rpar;

    题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...

  5. hdu 1242 找到朋友最短的时间 &lpar;BFS&plus;优先队列&rpar;

    找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...

  6. HDU 1428 漫步校园 &lpar;BFS&plus;优先队列&plus;记忆化搜索&rpar;

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

  7. hdu1839(二分&plus;优先队列,bfs&plus;优先队列与spfa的区别)

    题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...

  8. BFS&plus;优先队列&plus;状态压缩DP&plus;TSP

    http://acm.hdu.edu.cn/showproblem.php?pid=4568 Hunter Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  9. POJ - 2312 Battle City BFS&plus;优先队列

    Battle City Many of us had played the game "Battle city" in our childhood, and some people ...

随机推荐

  1. JAVA动态加载JAR

    // 生成JAR包D:\TestClass.jar package hand.java.loadjar; public class TestClass { private String sayHell ...

  2. Python for Infomatics 第13章 网页服务二(译)

    注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 13.4 JavaScript ...

  3. RN 项目导入WebStorm 组件没有依赖

    你需要在项目根目录   $ npm instal 恭喜你完成 但是依然报错 npm config set registry="registry.npmjs.org"  重新配置了一 ...

  4. 基本套接字编程(3) -- select篇

    1. I/O复用 我们学习了I/o复用的基本知识,了解到目前支持I/O复用的系统调用有select.pselect.poll.epoll.而epoll技术以其独特的优势被越来越多的应用到各大企业服务器 ...

  5. 【BZOJ-2295】我爱你啊 暴力

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 202  Solved: 141[Submit][St ...

  6. Linux 下绑定域名与IP地址

    在 Linux 下,hosts 文件的路径是 /etc/hosts,此文件需要有root权限才可编辑,条目也是通过“IP 域名”的格式将域名与IP进行绑定. 对 Linux 的 hosts 配置文件的 ...

  7. POJ 1731

    #include<iostream> #include<string> #include<algorithm> using namespace std; int m ...

  8. 在MVVMLight框架的ViewModel中实现NavigationService

    网上已经有很多方法了,比如通过Messenger来实现等等.这里我只讲述一种我比较喜欢的方法,因为它很方便 首先定义一个ViewModel基类,将所有ViewModel子类继承这个基类.在基类中定义 ...

  9. 轻量级jquery框架之--面板&lpar;panel&rpar;

    面板需求: (1)支持可拖拽,面板将作为后期的布局组件.window组件.alert组件的基础. (2)支持自定义工具栏,工具栏位置定义在面板底部,工具栏依赖toolbar组件. (3)支持加载JSO ...

  10. 踩过的坑—iphone手机H5样式兼容总结

    对一个前端开发者来说,最煎熬的莫过于"兼容"两个字了(说到这个词朋友们是不是身体一抖),哪怕对于工作多年的老油条来讲,也不是完全了解各种场景下的兼容性处理方法.在这里我就把我在工作 ...