杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring> #define MAX 999999 using namespace std; struct Node
{
int x,y;
int time;
}; char map[210][210];
int st[210][210];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int n,m,mintime; void Bfs(Node p)
{
Node now,next;
queue<Node> q;
int i;
q.push(p);
while(!q.empty())
{
now = q.front();
q.pop();
if(now.time >= mintime) //剪枝,超过最短时间的不用再走了
{
break;
}
if(map[now.x][now.y] == 'a') //找到天使时更新最短步骤
{
if(now.time < mintime)
{
mintime = now.time;
}
}
if(map[now.x][now.y] == 'x') //如果当前为门卫则多花1秒来杀死他
{
now.time += 1;
}
st[now.x][now.y] = 2; //标记此路径已经到达
next.time = now.time + 1; //下一步的时间加一
for(i = 0; i < 4; i++)
{
next.x = now.x + dir[i][0];
next.y = now.y + dir[i][1];
if(map[next.x][next.y] != '#' && st[next.x][next.y] == 0)
{
st[next.x][next.y] = 1; //标记此路径已经入队
q.push(next);
}
}
}
return ;
} int main()
{
int i,j;
Node now;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,'#',sizeof(map)); //初始化全为墙
memset(st,0,sizeof(st)); //初始化所有路径均未走过
mintime = MAX;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
cin >> map[i][j];
if(map[i][j] == 'r')
{
now.x = i;
now.y = j;
now.time = 0;
}
}
}
Bfs(now);
if(mintime == MAX)
{
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
else
{
printf("%d\n",mintime);
}
} return 0;
}
杭电 HDU 1242 Rescue的更多相关文章
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...
- HDU 1242 Rescue(优先队列)
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by ...
- HDU 1242 Rescue(BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by t ...
- HDU 1242 -Rescue (双向BFS)&&( BFS+优先队列)
题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- HDU 1242 Rescue (BFS(广度优先搜索))
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- 深入理解 IE haslayout
转载自Bubblings Blog 原文地址:http://riny.net/2013/haslayout/ 1.什么是haslayout layout是windows IE的一个私有概念,它决定了元 ...
- C++运算符重载为成员函数
#include<iostream> using namespace std; class Complex{ public: Complex(double r=0.0,double i=0 ...
- Session累计用户数据列表
OrderForm.html <body> <center> <h1 ><font size="20">Order Items& ...
- 网页往数据库里插数据要用utf8,否则就乱码
把网页的这行<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ...
- LintCode-子数组之和
题目描述: 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出 [-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. publ ...
- 网上下载的“上下3D”和“左右3D”影片该如何播放?
我们平常买的红蓝3D眼镜智能播放红蓝3D片源.网上找3D电影的时候,虽试图去找红蓝3D格式电影,但总会找到不少“左右格式”或者"上下格式"影片.正常播放后发现有两重画面.这种3D电 ...
- QT实现拖放文件(有例子,并且图文并茂,非常清楚)
转自:http://my.oschina.net/voler/blog/345722 目录[-] 0. 源代码下载地址 1. 简单文件拖放 2. 复杂文件拖放 3. 通过按钮来完成列表数据的转移 4. ...
- tcpdump抓包并保存成cap文件
首选介绍一下tcpdump的常用参数 tcpdump采用命令行方式,它的命令格式为: tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ] [ -i 网络接 ...
- 01_什么是Elasticsearch
Logstash是一个开源的用于收集,分析和存储日志的工具. Kibana4用来搜索和查看Logstash已索引的日志的web接口.这两个工具都基于 Elasticsearch. Logstash: ...
- CDLinux环境下WiFi密码破解
> 准备好所需软件以及上篇教程中使用Fbinstool制作的可启动U盘 2 > 解压CDLinux-0.9-spring-0412.iso到U盘的根目录 如图 3 > 打开fbin ...