简单题

 #include <iostream>
#include <cstdio>
#include <queue>
using namespace std; const int MAX=;
const int inf=;
int tim[MAX][MAX];
char maze[MAX][MAX];
int n,m;
int ai,aj;
typedef struct c{
int i,j,ti;
bool operator <(const c &A)const {
if(ti>A.ti) return true;
return false;
}
}Node;
Node tmp,pushed;
priority_queue<Node>que;
int dir[][]={,,,-,,,-,}; bool ok(int i,int j){
if(i>=&&i<n&&j>=&&j<m&&maze[i][j]!='#')
return true;
return false;
} bool bfs(){
int ti,tj;
while(!que.empty()){
tmp=que.top();
que.pop();
if(maze[tmp.i][tmp.j]=='r'){
printf("%d\n",tmp.ti);
return true;
}
for(int i=;i<;i++){
ti=tmp.i+dir[i][];
tj=tmp.j+dir[i][];
if(ok(ti,tj)){
if(maze[ti][tj]=='.'||maze[ti][tj]=='r'){
if(tmp.ti+<tim[ti][tj]){
tim[ti][tj]=tmp.ti+;
pushed.i=ti; pushed.j=tj; pushed.ti=tmp.ti+;
que.push(pushed);
}
}
else if(maze[ti][tj]=='x'){
if(tmp.ti+<tim[ti][tj]){
tim[ti][tj]=tmp.ti+;
pushed.i=ti; pushed.j=tj; pushed.ti=tmp.ti+;
que.push(pushed);
}
}
}
}
}
return false;
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++){
scanf("%s",maze[i]);
for(int j=;j<m;j++){
if(maze[i][j]=='a'){
ai=i; aj=j;
}
tim[i][j]=inf;
}
}
tim[ai][aj]=;
tmp.i=ai; tmp.j=aj; tmp.ti=;
que.push(tmp);
if(!bfs()){
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
while(!que.empty())
que.pop();
}
return ;
}

HDU 1242的更多相关文章

  1. hdu 1242 Rescue

    题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...

  2. HDU 1242 (BFS搜索+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目大意:多个起点到一个终点,普通点耗时1,特殊点耗时2,求到达终点的最少耗时. 解题思路: ...

  3. hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...

  4. hdu 1242 Rescue(bfs)

    此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...

  5. 杭电 HDU 1242 Rescue

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...

  6. HDU 1242 Rescue(优先队列)

    题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description   Angel was caught by ...

  7. HDU 1242 Rescue(BFS+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by t ...

  8. ZOJ-1649 Rescue BFS (HDU 1242)

    看题传送门: ZOJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 HDU http://acm.hdu.edu. ...

  9. HDU 1242 Rescue(BFS),ZOJ 1649

    题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...

  10. F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)

    经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...

随机推荐

  1. stack 栈

    其实今天我们主要讲的是搜索,但是留作业不知道怎么就突然全变成栈了. 其实栈和队列没什么区别,只是一个先进先出,一个先进后出.基本操作也是一样的. 栈(stack)又名堆栈,它是一种运算受限的线性表.其 ...

  2. B1800 [Ahoi2009]fly 飞行棋 数学模拟

    20分钟一遍AC,大水题,我的算法比较复杂,但是好理解,就是找可以凑出来一半周长的点来暴力枚举就行了. 题干: Description 给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依 ...

  3. Coursera Algorithms week1 查并集 练习测验:1 Social network connectivity

    题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which ...

  4. kafka参数在线修改

    当kafka集群单个节点出现磁盘满了,需要清理历史topic数据:方法如下 1): 停掉kafka进程,将kafka的server.properties中的log.retention.hours=1/ ...

  5. HttpClient短信接口

    HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...

  6. C#,Java,MD5加密对等实现

    1.c#实现 /* *加密生成MD5 */ public static String MD5(string s) { ', 'a', 'b', 'c', 'd', 'e', 'f' }; MD5 md ...

  7. 精确获取对象的类型:Object.prototype.toString()

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString

  8. Linux的那点事

    1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...

  9. 国内DNS服务器地址

    114DNS114.114.114.114114.114.115.115 腾讯119.29.29.29 百度180.76.76.76 阿里223.5.5.5223.6.6.6 [THE END]

  10. Windows server 2008R2系统登录密码破解

    服务器密码忘记,或者被恶意修改,系统被入侵,都是很让人烦心的事情,我试过很多方法,包括使用PE工具删除C盘Windows\System\config里面的SAM文件,可是过程都相当华美,结果都相当杯具 ...