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 ...
随机推荐
- 2017全球互联网技术大会回顾(附PPT)
有幸遇见 GITC2017上海站,刚好遇见你! 为期两天(6.23~24)的GITC大会在上海举行,我有幸参加了24号的那场,也就是上周六,之所以今天才来回顾,是我想等PPT出来后分享给大家! 这应该 ...
- [leetcode-582-Kill Process]
Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...
- php测试题
1. LAMP具体结构不包含下面哪种(A) A:Windows系统 B:Apache服务器 C:MySQL数据库 D:PHP语言 2. 以下哪个SQL语句是正确的(D) A:insert into u ...
- nuget挂了吗?
[nuget.org] Unable to load the service index for source https://api.nuget.org/v3/index.json. 发送请求时出错 ...
- Java读取数据源相关信息
一.采用读取数据源配置文件的方式 package com.ofsp.utils; import java.io.IOException; import java.io.InputStream; imp ...
- PeopleCode事件和方法只用于online界面不能用于组件接口(component interface)
在使用CI过程中,哪些方法是不能使用的.以下为PeopleBook解释的内容. 一.搜索框代码不执行:SearchInit, SearchSave, and RowSelect events 意味着使 ...
- HashMap源码深入研究
简介 HashMap是采用链表和位桶来来实现的,由于一个位桶存在元素太多会导致get效率低,因此在jdk1.8中采用的红黑树实现,当链表长度大于TREEIFY_THRESHOLD(值为8)时会转换为红 ...
- 006.Adding a controller to a ASP.NET Core MVC app with Visual Studio -- 【在asp.net core mvc 中添加一个控制器】
Adding a controller to a ASP.NET Core MVC app with Visual Studio 在asp.net core mvc 中添加一个控制器 2017-2-2 ...
- Python-WXPY实现微信监控报警
概述: 本文主要分享一下博主在学习wxpy 的过程中开发的一个小程序.博主在最近有一个监控报警的需求需要完成,然后刚好在学习wxpy 这个东西,因此很巧妙的将工作和学习联系在一起. 博文中主要使用到的 ...
- Django学习(八)---修改文章和添加文章
博客页面的修改文章和添加新文章 从主页点击不同文章的超链接进入文章页面,就是传递了一个id作为参数,然后后台代码根据这个参数从数据库中取出来对应的文章,并把它传递到前端页面 修改文章和添加新文章,是要 ...