HDU 1242 Rescue 营救天使
Description
Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach Angel" is to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or her?) to move into the grid. We assume that we moving up, down, right, left takes us 1 unit time, and killing a guard takes 1 unit time, too. And we are strong enough to kill all the guards.
You have to calculate the minimal time to approach Angel. (We can move only UP, DOWN, LEFT and RIGHT, to the neighbor grid within bound, of course.)
Input
Then N lines follows, every line has M characters. "." stands for road, "a" stands for Angel, and "r" stands for each of Angel's friend.
Process to the end of the file.
Output
# .a #..r.
#..#x... ..#..#.#
#...##.. .#...... ........
Sample Output
#include<cstdio>
#include<string.h>
#include<queue>
using namespace std;
int m,n,i,j,ans,map[][],ex,ey,bx,by;
int dx[]={-,,,};
int dy[]={,,-,};
char str[];
struct stu
{
int x,y,step;
bool friend operator <(stu a,stu b)
{
return a.step>b.step;
}
}st;
int bfs()
{
priority_queue<stu>que;
int x,y,i,time;
stu next; st.x=bx;
st.y=by;
st.step=;
que.push(st);
while(!que.empty())
{ st=que.top();
que.pop();
time=st.step;
x=st.x;
y=st.y;
for(i=;i<;i++)
{
st.x=x+dx[i];
st.y=y+dy[i];
if(st.x>= &&st.y>=&&st.x<m&&st.y<m&&map[st.x][st.y]!=)
{
if(st.x == ex && st.y == ey)
{
return time+;
}
if(map[st.x][st.y] == )
{
st.step=time+;
}
else
{
st.step=time+;
}
map[st.x][st.y]=;
que.push(st);
}
}
}
return ;
}
int main()
{
while(scanf("%d %d",&m,&n)!=EOF)
{
memset(map,,sizeof(map));
for(i = ; i < m ; i++)
{
scanf("%s",&str);
for(j = ;j < n ; j++)
{
if(str[j] == '.')
{
map[i][j]=;
}
if(str[j] == 'x')
{
map[i][j]=;
}
if(str[j] == 'a')
{
map[i][j]=;
ex=i;
ey=j;
}
if(str[j] == 'r')
{
map[i][j]=;
bx=i;
by=j;
}
}
}
/* for( i = 0 ; i < m ; i++)
{
for(j =0 ; j < n ; j++)
{
printf("%d ",map[i][j]);
if(j == n-1)
{
printf("\n");
}
}
} */
map[bx][by]=;
ans=bfs();
if(ans)
printf("%d\n",ans);
else
printf("Poor ANGEL has to stay in the prison all his life.\n"); }
}
HDU 1242 Rescue 营救天使的更多相关文章
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- 杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- 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/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- the little schemer 笔记(2)
第二章 Do it, Do it Again, and Again, and Again... 假设l是 (Jack Sprat could eat no chicken fat) 那么 (lat? ...
- Baker Vai LightOJ - 1071
题意:类似传纸条 方法: 把他要求的操作(一个人来回),转化为两个人同时走,除了开始和结束位置只能走不同路,得到的分数和的最大值即可. 一开始想到要定义的状态,是两个人的x(行)和y(列)坐标.这样时 ...
- 18.5.1使用Proxy和InvocationHandler创建动态代理
package d18_5_1; public interface Person { void walk(); void sayHello(String name); } package d18_5_ ...
- h5-15-svg格式图片
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- DHCP服务简单搭建步骤
服务端:sishen_63 IP:192.168.1.63 客户端:sishen_64 IP:192.168.1.64 此外,因为本实验实在虚拟机中做的,所以对虚拟机还要做如下设置: 服务 ...
- Outlook读取奇妙清单Wunderlist日历失败的解决办法
错误: Outlook.com日历订阅奇妙清单的日历链接时报错 This calendar wasn't updated because of a problem with the publisher ...
- scrollTop、offsetTop、clientTop
1.offsetTop: obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置. 2.clientTop: 这个返回的是元素周围边框的厚度, ...
- JS进阶-特殊形式的函数-返回函数的函数/重写自己的函数
返回函数的函数 // 返回函数的函数 function a() { alert("aa"); return function () { alert("bb"); ...
- 在自己的工程中使用ijkplayer的功能
最近在做一个软解视频叠加硬解视频的方案,网上看了很多教程,始终不得要领.虽然ijkplayer提供了ijkplayer-example这个示例工程,但对于初入安卓的人来说,要将ijkplayer整合到 ...
- COGS 886. [USACO 4.2] 完美的牛栏
★★☆ 输入文件:stall4.in 输出文件:stall4.out 简单对比时间限制:1 s 内存限制:128 MB USACO/stall4(译by Felicia Crazy) ...