杭电acm 1242
来源:互联网 发布:程序员面试问题及答案 编辑:程序博客网 时间:2024/06/10 03:34
Rescue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18371 Accepted Submission(s): 6557
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
题目意思:
a先生在监狱,他的朋友r来救他(注意:r可能不止一个人)‘.’为普通的路每走一个时间加一,‘x’为狱警每过一个时间加二 ‘#’为墙不能通过。现在要你输出最短的将a先生解救出来的时间。
这里要注意的是可能不止一个朋友所以应该由a先生去找朋友,而不是由朋友找a。
0 0
- 杭电acm 1242
- 杭电ACM 1003
- 杭电 ACM 2016
- 杭电acm 1010
- 杭电 acm 1045
- 杭电ACM-1010
- 杭电ACM 1172
- 杭电ACM 1174
- 杭电ACM 1175
- 杭电ACM 分类
- 杭电ACM分类
- 杭电acm 1000
- 杭电acm 1001
- 杭电acm 1002
- 杭电acm分类
- 杭电acm分类
- 杭电 ACM 1004
- 杭电 ACM 1007
- hadoop集群配置
- Android sqlite 数据库操作
- SQL优化--逻辑优化--数据库的约束规则与语义优化
- 【转】 计算几何中的精度问题
- jpa集合元素的映射
- 杭电acm 1242
- 忘记了phpmyadmin的密码的解决方法
- Effective C++ 学习笔记2
- 单例模式
- js正则表达式之中文验证
- hdu 5018 Revenge of Fibonacci
- 流媒体常见资源
- Conclusion:使用sqlserver 2008 R2 构建多维数据源
- mongodb启动显示Unclean shutdown detected.解决方法