[ACM] HDU 1242 Rescue (优先队列)
来源:互联网 发布:字体管家mac版 编辑:程序博客网 时间:2024/05/01 12:46
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
解题思路:
简单的优先队列题目。复习一下优先队列用法.
代码:
优先队列用法:
运行:
96532
23569
优先级 值
9 5
8 2
6 1
2 3
1 4
0 0
- [ACM] HDU 1242 Rescue (优先队列)
- [ACM] HDU 1242 Rescue (优先队列)
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- [ACM] hdu 1242 Rescue (BFS+优先队列)
- hdu 1242Rescue(bfs+优先队列)
- hdu 1242 Rescue (优先队列+bfs)
- HDU 1242 Rescue(BFS +优先队列)
- hdu 1242 Rescue (优先队列)
- 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(优先队列)
- HDU-1242-Rescue(优先队列+BFS)
- HDU 1242 Rescue(BFS+优先队列)
- Android 编程下的 EditView 阻止软键盘自动弹出__图片资源文件后缀不能为.ico
- 约瑟夫环问题 循环链表
- MapReduce的处理流程(一)
- 用过滤器解决全站中文数据提交乱码问题
- Binary Tree Inorder Traversal
- [ACM] HDU 1242 Rescue (优先队列)
- poj 3274 Gold Balanced Lineup
- JavaScript 知识点总结-3
- Android中JNI的使用方法
- 类和对象
- Eclipse --- 常用配置及快捷键
- 黑马程序员——类与对象
- C++基础---有返回值类型函数(返回非引用类型)
- [ACM] POJ 3740 Easy Finding (DFS)