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、注意一下优先级判断就行了

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 110 struct Node
{
int x,y,t,r; //坐标,时间,剩余加速时间
bool operator <(const Node &T)const{
if(t!=T.t)return t>T.t;
return r<T.r;
}
}; int n,m;
int sx,sy;
int vis[N][N][];
char mpt[N][N];
int dir[][]={-,,,,,-,,}; void bfs()
{
Node now,next;
priority_queue<Node> q;
memset(vis,,sizeof(vis));
now.x=sx;
now.y=sy;
now.t=now.r=;
vis[sx][sy][]=;
q.push(now);
while(!q.empty())
{
now=q.top();
q.pop();
if(mpt[now.x][now.y]=='E'){
printf("%d\r\n",now.t);
return;
}
for(int i=;i<;i++){
next=now;
next.x+=dir[i][];
next.y+=dir[i][];
next.t+=;
if(next.r>=) {next.t--;next.r--;}
if(next.x>= && next.x<=n && next.y>= && next.y<=m && mpt[next.x][next.y]!='#'){
if(mpt[next.x][next.y]=='A') next.r=;
if(!vis[next.x][next.y][next.r]){
vis[next.x][next.y][next.r]=;
q.push(next);
}
}
}
}
printf("Please help BH!\r\n");
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf(" %c",&mpt[i][j]);
if(mpt[i][j]=='S'){
sx=i;
sy=j;
}
}
}
bfs();
}
return ;
}

[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. 1084: [SCOI2005]最大子矩阵 - BZOJ

    Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. Input 第一行为n,m,k(1≤n≤100,1≤m≤2 ...

  2. svn: E155004: ..(path of resouce).. is already locked

    svn: E155004: ..(path of resouce).. is already locked I'm getting an error when trying to commit a c ...

  3. 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZdef”,要求输出循环左移3位后的结果,即“XYZdefabc”。是不是很简单?OK,搞定它!

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  4. JAVA 获取系统环境变量

    分享代码: package com.base.entity; import java.io.Serializable; import java.util.Comparator; /** * 系统环境变 ...

  5. 数字式PID控制的应用总结

    PID控制是一个二阶线性闭环控制器,通过调整比例.积分和微分三项参数,使得大多数的工业控制系统获得良好的闭环控制性能.PID控制优点:a. 技术成熟,b. 易被人们熟悉和掌握,c. 不需要建立数学模型 ...

  6. Eclipse插件开发

    最近在做Eclipse的插件开发,目前是在Eclipse3.x环境上进行开发,之后迁移到Eclipse4.x环境.会贡献在插件开发过程中遇到的所有问题以及相关技巧,敬请期待. SWT开发 JFace开 ...

  7. VC6.0环境安装STLport-5.2.1

    今天安装STLport,网上搜资料安装好久,都不行,因为STLport 的版本不对,我这是STLport-5.2.1新版本. (注意:下面的步骤都在一个cmd里操作,很简单的原因:环境变量啊) 1.首 ...

  8. 在MySQL中使用init-connect与binlog来实现用户操作追踪记录

    在MySQL中使用init-connect与binlog来实现用户操作追踪记录 分类: MySQL 前言: 测试环境莫名其妙有几条重要数据被删除了,由于在binlog里面只看到是公用账号删除的,无法查 ...

  9. poj 3268 Silver Cow Party(最短路,正反两次,这个模版好)

    题目 Dijkstra,正反两次最短路,求两次和最大的. #define _CRT_SECURE_NO_WARNINGS //这是找出最短路加最短路中最长的来回程 //也就是正反两次最短路相加找最大的 ...

  10. 关联式容器(associative containers)

    关联式容器(associative containers) 根据数据在容器中的排列特性,容器可分为序列式(sequence)和关联式(associative)两种. 标准的STL关联式容器分为set( ...