NYOJ--353--bfs+优先队列--3D dungeon
/* 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的更多相关文章
- nyoj 353 3D dungeon
3D dungeon 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 You are trapped in a 3D dungeon and need to find ...
- NYOJ353 3D dungeon 【BFS】
3D dungeon 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...
- 3D dungeon
算法:广搜: 描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is comp ...
- POJ 1724 ROADS(BFS+优先队列)
题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...
- hdu 1242 找到朋友最短的时间 (BFS+优先队列)
找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)
题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...
- BFS+优先队列+状态压缩DP+TSP
http://acm.hdu.edu.cn/showproblem.php?pid=4568 Hunter Time Limit: 2000/1000 MS (Java/Others) Memo ...
- POJ - 2312 Battle City BFS+优先队列
Battle City Many of us had played the game "Battle city" in our childhood, and some people ...
随机推荐
- http请求的完整过程
HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1. 建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该 ...
- 在jupyter notebook中同时安装python2和python3
之前讨论过在anaconda下安装多个python版本,本期来讨论下,jupyter notebook中怎样同时安装python2.7 和python3.x. 由于我之前使用的jupyter note ...
- 【Android Developers Training】 33. 接收来自其它应用的简单数据
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 使用Cain&Abel进行网络嗅探
启动Cain&Abel并切换到"sniffer(嗅探)"标签. 第一步:需要对Cain&Abel进行配置,先单击最上面的"Configure(配置)&qu ...
- Unity 游戏框架搭建 (五) 简易消息机制
什么是消息机制? 23333333,让我先笑一会. 为什么用消息机制? 三个字,解!!!!耦!!!!合!!!!. 我的框架中的消息机制用例: 1.接收者 ``` using UnityEngine ...
- 64位Win10系统安装Mysql5.7.11
最近在装了64位Win10系统的mac book笔记本上用mysql-installer-community-5.7.11.0安装Mysql5.7.11,在配置mysql server时老是卡住,报错 ...
- 百度BAE环境搭建
一.申请 1.http://bce.baidu.com/index.html 2.购买应用引擎BAE需要实名认证:http://console.bce.baidu.com/qualify/#/qual ...
- Delphi临界区的使用
在开发一个平板点餐软件后台订单打印程序时,使用线程订单打印,为防打印阻塞使用临界区. 类: type MYPARA=record title:pchar; //标题 str:pchar; flag:i ...
- Spring HandlerInterceptor
1.Spring HandlerInterceptor 可以组成一个chain. 这个接口有三个方法: public interface HandlerInterceptor { /** * Inte ...
- synchronized的作用
一.同步方法 public synchronized void methodAAA(){ //-. } 锁定的是调用这个同步方法的对象 测试:a.不使用这个关键字修饰方法,两个线程调用同一个对象的这个 ...