[ACM] hdu 1242 Rescue (BFS+优先队列)
来源:互联网 发布:齐鲁石化网络电视台 编辑:程序博客网 时间:2024/05/01 09:21
Rescue
Problem Description
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.
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.)
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
First line contains two integers stand for N and M.
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.
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
For each test case, your program should output a single integer, standing for the minimal time needed. If such a number does no exist, you should output a line containing "Poor ANGEL has to stay in the prison all his life."
Sample Input
7 8#.#####.#.a#..r.#..#x.....#..#.##...##...#..............
Sample Output
13
Author
CHEN, Xue
Source
ZOJ Monthly, October 2003
一个地图中,给定起点和终点,上下左右走,每走一步花1个单位时间,遇到怪,需要杀死怪,额外花1个单位时间,求从起点到终点最少花多少分钟。
主要思路是广度优先搜索,但因为其中有怪,需要额外花时间,那么对于队列里面的每个节点(保存x,y坐标和当前所用时间),并不是“公平”的,要想最少花时间,那么每次在队头取出的元素应该是队列里面所用时间最少的,所以应该用优先队列。
代码:
0 0
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- hdu 1242Rescue(bfs+优先队列)
- hdu 1242 Rescue (优先队列+bfs)
- HDU 1242 Rescue(BFS +优先队列)
- hdu 1242 Rescue(bfs+优先队列)
- HDU 1242 Rescue 优先队列+BFS
- HDU 1242 Rescue(BFS,优先队列)
- HDU 1242 Rescue(BFS+优先队列)
- hdu-1242-Rescue(优先队列 BFS)
- HDU 1242 Rescue(优先队列 + 多源BFS)
- hdu 1242 Rescue(BFS优先队列)
- HDU 1242 Rescue (BFS+优先队列)
- hdu 1242 Rescue (bfs+优先队列)
- HDU 1242 Rescue (BFS+优先队列)
- HDU 1242 Rescue(优先队列+bfs)
- HDU 1242 Rescue【优先队列BFS】
- hdu 1242 Rescue(BFS+优先队列)
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
- uva 524 回溯法
- weka中的各算法说明
- 如何阅读一个复杂的类型
- 对象的序列化与反序列化---IO学习笔记(四)
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- SpringMVC 集成JSR303数据校验
- 栈的顺序存储实现
- HDU 1874--畅通工程续【最短路 && floyd && 水题】
- [ACM] hdu 2717 Catch That Cow (BFS)
- Get Luffy Out (poj 2723 二分+2-SAT)
- LeetCode之Recover Binary Search Tree
- OC之集合家族
- machine learning in coding(python):拼接原始数据;生成高次特征