Escape
 
 
Description

BH is in a maze,the maze is a matrix,he wants to escape!

Input

The input consists of multiple test cases.

For each case,the first line contains 2 integers N,M( 1 <= N, M <= 100 ).

Each of the following N lines contain M characters. Each character means a cell of the map.

Here is the definition for chracter.

For a character in the map:

'S':BH's start place,only one in the map.

'E':the goal cell,only one in the map.

'.':empty cell.

'#':obstacle cell.

'A':accelerated rune.

BH can move to 4 directions(up,down,left,right) in each step.It cost 2 seconds without accelerated rune.When he get accelerated rune,moving one step only cost 1 second.The buff lasts 5 seconds,and the time doesn't stack when you get another accelerated rune.(that means in anytime BH gets an accelerated rune,the buff time become 5 seconds).

Output

The minimum time BH get to the goal cell,if he can't,print "Please help BH!".

Sample Output

5 5
....E
.....
.....
##...
S#...
5 8
........
........
..A....A
A######.
S......E

Sample Output
Please help BH!
12

BFS、注意一下优先级判断就行了

  1. #include <iostream>
  2. #include <queue>
  3. #include <cstdio>
  4. #include <cstring>
  5. using namespace std;
  6. #define N 110
  7.  
  8. struct Node
  9. {
  10. int x,y,t,r; //坐标,时间,剩余加速时间
  11. bool operator <(const Node &T)const{
  12. if(t!=T.t)return t>T.t;
  13. return r<T.r;
  14. }
  15. };
  16.  
  17. int n,m;
  18. int sx,sy;
  19. int vis[N][N][];
  20. char mpt[N][N];
  21. int dir[][]={-,,,,,-,,};
  22.  
  23. void bfs()
  24. {
  25. Node now,next;
  26. priority_queue<Node> q;
  27. memset(vis,,sizeof(vis));
  28. now.x=sx;
  29. now.y=sy;
  30. now.t=now.r=;
  31. vis[sx][sy][]=;
  32. q.push(now);
  33. while(!q.empty())
  34. {
  35. now=q.top();
  36. q.pop();
  37. if(mpt[now.x][now.y]=='E'){
  38. printf("%d\r\n",now.t);
  39. return;
  40. }
  41. for(int i=;i<;i++){
  42. next=now;
  43. next.x+=dir[i][];
  44. next.y+=dir[i][];
  45. next.t+=;
  46. if(next.r>=) {next.t--;next.r--;}
  47. if(next.x>= && next.x<=n && next.y>= && next.y<=m && mpt[next.x][next.y]!='#'){
  48. if(mpt[next.x][next.y]=='A') next.r=;
  49. if(!vis[next.x][next.y][next.r]){
  50. vis[next.x][next.y][next.r]=;
  51. q.push(next);
  52. }
  53. }
  54. }
  55. }
  56. printf("Please help BH!\r\n");
  57. }
  58. int main()
  59. {
  60. while(scanf("%d%d",&n,&m)!=EOF)
  61. {
  62. for(int i=;i<=n;i++){
  63. for(int j=;j<=m;j++){
  64. scanf(" %c",&mpt[i][j]);
  65. if(mpt[i][j]=='S'){
  66. sx=i;
  67. sy=j;
  68. }
  69. }
  70. }
  71. bfs();
  72. }
  73. return ;
  74. }

[swustoj 1023] Escape的更多相关文章

  1. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  2. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  3. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  4. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  5. 【BZOJ-1340】Escape逃跑问题 最小割

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 264  Solved: 121[Submit] ...

  6. LYDSY热身赛 escape

    Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...

  7. javascript escape()函数和unescape()函数

    javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...

  8. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  9. escape,encodeURI,encodeURIComponent的区别

    escape是对字符串进行编码而另外两种是对URL. encodeURI方法不会对下列字符编码 ASCII字母 数字 ~!@#$&*()=:/,;?+'encodeURIComponent方法 ...

随机推荐

  1. win7旗舰版安装office2007后打开文件提示找不到proplusww.msi

    今天第一次打开2007的excel,出现错误如下: 解决办法: 转自:http://blog.163.com/huacai9420@126/blog/static/521585422011911524 ...

  2. CSS3属性box-shadow使用教程,css3box-shadow

    CSS3的box-shadow属性可以让我们轻松实现图层阴影效果.我们来实战详解一下这个属性. 1. box-shadow属性的浏览器兼容性先来看一个这个属性的浏览器兼容性: Opera: 不知道是从 ...

  3. 首次push本地代码到github上出现的问题及解决方案

    刚创建的github版本库,在push代码时出错: $ git push -u origin masterTo git@github.com:******/Demo.git ! [rejected] ...

  4. java web项目 。classpath 文件解析

    eclipse工程中.classpath文件含义: 下面是一个.classpath文件内容: < ?xml version="1.0" encoding="UTF- ...

  5. mMathf -》 Unity3d通用脚本

    public class mMathf { /// <summary> /// 辗转 相除法 求 最大公约数 /// a / b = k /// a % b = r /// 原理 gcd( ...

  6. Checkbox框全选操作,form表单提交与jquery ajax提交两种处理方式

    //1.jquery ajax<script type="text/javascript"> $(function(){ var basePath = $(" ...

  7. XEE介绍

    摘要: XMl Entity Expansion(攻击)某种程度上类似于 XML Entity Expansion,但是它主要试图通过消耗目标程序的服务器环境来进行DOS攻击的.这种攻击基于XML E ...

  8. Chpater 10: Sorting

    Internal Sort: Bubble  O(n2) Selection O(n2) Insertion O(n2) Shell O(nlogn) Merge O(nlogn) Heap O(nl ...

  9. POJ 3111

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 5177   Accepted: 1411 Case Time ...

  10. 【QT】计时器制作

    应小伙伴的要求,做一个小计时器.功能是点击开始就从00:00:00开始计时,点击暂停就暂停计时,点击停止就停止计时. 界面如上图,使用ui设计师直接拖的.按钮和图标的图片都是网上下载的.用美图秀秀抠成 ...