简单题

 #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. DCloud-MUI:窗口管理

    ylbtech-DCloud-MUI:窗口管理 通过预加载解决切页白屏问题,通过封装原生动画解决SPA模式的动画卡顿 1.返回顶部 1.页面初始化 在app开发中,若要使用HTML5+扩展api,必须 ...

  2. PCB Genesis加邮票孔(邮票孔增加方向判断--左右上下)实现算法

    之前没解决的问题,当时一下卡在用户界面选择邮票孔增加的方向(上下左右) 与邮票孔实际方位之前的逻辑与非判断上卡壳了,导致一下没进展下去. 回头看原来如此简单 ,将此点记录一下. 1.垂直线定义:80- ...

  3. Help Me with the Game(模拟)

    http://poj.org/problem?id=2996 #include<stdio.h> #include<string.h> ][]; void find1(char ...

  4. MySQL命令学习之技巧(博主推荐)

    关于,这篇博客呢,是

  5. sql 改字段名

    sp_rename '[zErpMini].[dbo].[STK_Stock].Isextension','IsExtened'

  6. 网站html代码解析

    1.什么是HTML文件?HTML中文叫做“超文本标记语言”,一个HTML文件不仅包含文本内容,还包含一些标记,一个HTML文件的后缀名是.htm或者是.html.用文本编辑器(Dreamweaver) ...

  7. 自动换行 word-break:break-all和word-wrap:break-word

    1.word-break:break-all;当内容(比如很长的一个单词)到每行的末端时,它会把单词截断显示一部分,下一行显示后一部分. 2.word-wrap:break-word;当内容(比如很长 ...

  8. 3.0 Windows和Linux双系统安装(3)

    3.0 Windows和Linux双系统安装(3) 3.1 精简的安装步骤如下:(如果已经有了前面两篇教程的安装经验,推荐看完3.1即可动手了) 双系统很多开发新人会用到,而且比起虚拟机好处是运行效率 ...

  9. 安卓Queue的使用

    Queue的成员函数        add        增加一个元索                     如果队列已满,则抛出一个IIIegaISlabEepeplian异常       rem ...

  10. Scala类型系统——高级类类型(higher-kinded types)

    高级类类型就是使用其他类型构造成为一个新的类型,因此也称为 类型构造器(type constructors).它的语法和高阶函数(higher-order functions)相似,高阶函数就是将其它 ...