1. /*
  2. Name: NYOJ--3533D dungeon
  3. Author: shen_渊
  4. Date: 15/04/17 15:10
  5. Description: bfs()+优先队列,队列也能做,需要开一个vis[35][35][35]标记
  6. */
  7.  
  8. #include<iostream>
  9. #include<queue>
  10. using namespace std;
  11. struct node{
  12. int x,y,z,steps;
  13. node():steps(){
  14. };
  15. bool operator <(const node &a)const {
  16. return steps>a.steps;
  17. }
  18. };
  19. int bfs();
  20. priority_queue<node> q;
  21. int l,r,c;
  22. node s,e;
  23. ][][];
  24. ] = {{,,},{-,,},{,,},{,-,},{,,},{,,-}};
  25. int main()
  26. {
  27. // freopen("in.txt","r",stdin);
  28. while(cin>>l>>r>>c,l+r+c){
  29. ; i<l; ++i){
  30. ; j<r; ++j){
  31. cin>>map[i][j];
  32. ; k<c; ++k){
  33. if(map[i][j][k] == 'S')s.x = j,s.z = i,s.y = k;
  34. if(map[i][j][k] == 'E')e.x = j,e.y = k,e.z = i;
  35. }
  36. }
  37. }
  38. int t;
  39. if (t=bfs())
  40. cout << "Escaped in " << t << " minute(s)." << endl;
  41. else
  42. cout << "Trapped!" << endl;
  43. }
  44. ;
  45. }
  46. int bfs(){
  47. while(!q.empty()) q.pop();
  48. q.push(s);
  49. while(!q.empty()){
  50. node temp = q.top();q.pop();
  51. ; i<; ++i){
  52. node a = temp;
  53. a.z += dir[i][];
  54. a.x += dir[i][];
  55. a.y += dir[i][];
  56. a.steps++;
  57. if(a.z == e.z&& a.x==e.x&&a.y==e.y)return a.steps;
  58. if(map[a.z][a.x][a.y] == '#')continue;
  59. || a.z>=l)continue;
  60. || a.x>=r)continue;
  61. || a.y>=c)continue;
  62. q.push(a);
  63. map[a.z][a.x][a.y] = '#';
  64. }
  65. }
  66. ;
  67. }

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(BFS+优先队列)

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

  5. hdu 1242 找到朋友最短的时间 (BFS+优先队列)

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

  6. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

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

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

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

  8. BFS+优先队列+状态压缩DP+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+优先队列

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

随机推荐

  1. 2017全球互联网技术大会回顾(附PPT)

    有幸遇见 GITC2017上海站,刚好遇见你! 为期两天(6.23~24)的GITC大会在上海举行,我有幸参加了24号的那场,也就是上周六,之所以今天才来回顾,是我想等PPT出来后分享给大家! 这应该 ...

  2. [leetcode-582-Kill Process]

    Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...

  3. php测试题

    1. LAMP具体结构不包含下面哪种(A) A:Windows系统 B:Apache服务器 C:MySQL数据库 D:PHP语言 2. 以下哪个SQL语句是正确的(D) A:insert into u ...

  4. nuget挂了吗?

    [nuget.org] Unable to load the service index for source https://api.nuget.org/v3/index.json. 发送请求时出错 ...

  5. Java读取数据源相关信息

    一.采用读取数据源配置文件的方式 package com.ofsp.utils; import java.io.IOException; import java.io.InputStream; imp ...

  6. PeopleCode事件和方法只用于online界面不能用于组件接口(component interface)

    在使用CI过程中,哪些方法是不能使用的.以下为PeopleBook解释的内容. 一.搜索框代码不执行:SearchInit, SearchSave, and RowSelect events 意味着使 ...

  7. HashMap源码深入研究

    简介 HashMap是采用链表和位桶来来实现的,由于一个位桶存在元素太多会导致get效率低,因此在jdk1.8中采用的红黑树实现,当链表长度大于TREEIFY_THRESHOLD(值为8)时会转换为红 ...

  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 ...

  9. Python-WXPY实现微信监控报警

    概述: 本文主要分享一下博主在学习wxpy 的过程中开发的一个小程序.博主在最近有一个监控报警的需求需要完成,然后刚好在学习wxpy 这个东西,因此很巧妙的将工作和学习联系在一起. 博文中主要使用到的 ...

  10. Django学习(八)---修改文章和添加文章

    博客页面的修改文章和添加新文章 从主页点击不同文章的超链接进入文章页面,就是传递了一个id作为参数,然后后台代码根据这个参数从数据库中取出来对应的文章,并把它传递到前端页面 修改文章和添加新文章,是要 ...