[swustoj 1023] Escape
BH is in a maze,the maze is a matrix,he wants to escape!
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).
The minimum time BH get to the goal cell,if he can't,print "Please help BH!".
Sample Output
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的更多相关文章
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 简单明了区分escape、encodeURI和encodeURIComponent
一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...
- c#模拟js escape方法
public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...
- 【BZOJ-1340】Escape逃跑问题 最小割
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ...
- LYDSY热身赛 escape
Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...
- javascript escape()函数和unescape()函数
javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- escape,encodeURI,encodeURIComponent的区别
escape是对字符串进行编码而另外两种是对URL. encodeURI方法不会对下列字符编码 ASCII字母 数字 ~!@#$&*()=:/,;?+'encodeURIComponent方法 ...
随机推荐
- MySQL 体系架构
MySQL 体系架构 本篇文章是对mysql体系结构进行了详细的分析介绍,需要的朋友参考下 上面一图是mysql的概览图,我们从上往下看, 我们把上面一图一分为二,我们可以吧它分为两个部分, 1,是c ...
- hadoop 技巧
通过--config指定不同的集群 bin/hadoop --config ./conf_time/ dfs -ls /user/rd/*/for_*/ip_table/output/ rd下是都读写 ...
- CSDN——【低调的草原狼】——Ext4.2学习目录整理
最近在研究ExtJS,发现CSDN中有个博客中一系列文档非常优秀,但是没有对目录进行整理,在此稍作整理,也为以后自己研究打下一个基础: 原文作者:低调的草原狼 目录: 1.ExtJS4.2学习 ...
- 指针强转和void*
C语言中,任何一个变量都必须占有一个地址,而这个地址空间内的0-1代码就是这个变量的值.不同的数据类型占有的空间大小不一,但是他们都必须有个地址,而这个地址就是硬件访问的依据,而名字只是提供给程序员的 ...
- centos6.5\win7双系统安装配置
一.安装所需软件 1.分区助手专业版PACNPro.exe(必需):用来对硬盘分区,将磁盘的一部分格式化成Linux可以识别的ext3格式 2.Ext2Fsd(硬盘安装必需,光盘安装不用):因为Win ...
- java 伪静态的方法
1.jar包支持urlrewritefilter-4.0.3.jar http://files.cnblogs.com/simpledev/urlrewritefilter-4.0.3.rar 2. ...
- ECMALL目录结构设置与数据库表
[Ecmall]ECMALL目录结构设置与数据库表 最近在做ecmall的开发,ecmall在开源方面还有待进步啊,官方没有提供开发文档,也没有关于系统架构组织的贡献,使用者都要自己从0开始,官方 ...
- Lua 的数据结构
1. Arrays: 注意 #(data), # 加上 table名字 == size of data = {}; , do --行 , do --列 data[(y-)*+x] = (y-)*+x; ...
- python 解析 xml
<taskList nextId="62292"> <task module="reliability" owner="vprovo ...
- Hadoop基础教程之搭建开发环境及编写Hello World
整个Hadoop是基于Java开发的,所以要开发Hadoop相应的程序就得用JAVA.在linux下开发JAVA还数eclipse方便. 1.下载 进入官网:http://eclipse.org/do ...