简单题

 #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. Mybatis:目录

    ylbtech-MyBatis:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbte ...

  2. PCB MS SQL 排序应用---相邻数据且相同合并处理

    这是一个很有趣SQL数据处理应用,具体需求如下 ERP需要工程将物料编码相邻的编码合并求和BOM用量,巧妙的用到了已有排序号与分组排序号之间的差值求解 示例: 原数据: 要求转换: 实际转换后数据: ...

  3. 玩游戏(dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566 #include <stdio.h ...

  4. [Swift]LeetCode1071.字符串的最大公因子 | Greatest Common Divisor of Strings

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. CALayer(一)

    CALayer CALayer和UIView CALayer和UIView相比--CALayer少了事件处理的功能,所以更加轻量级,性能更好一点,这就说明如果有一些和用户交互的东西是不建议用CALay ...

  6. A - Supermarket

    Problem description We often go to supermarkets to buy some fruits or vegetables, and on the tag the ...

  7. JSP_内置对象_session

    session表示客户端与服务器的一次会话. Web中的session指的是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间. 从上述定义中可以看到,s ...

  8. 点击button 触发另一个button 事件

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs&quo ...

  9. <转>c++引用与指针的区别(着重理解)

     ★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名.  ★ 区别: 1. 指针是一个实体,而引用仅是个别名: 2. 引用使用时无需解引用(*),指 ...

  10. Linux 重要文件目录

    文件系统层次化标准(Filesystem Hierarchy Standard)[FHS] 树形结构 /boot 开机所需文件——内核开机菜单以及所需的配置文件等 /dev 以文件形式存放任何设备与接 ...