Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27126    Accepted Submission(s): 9607


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.)
 

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.
 

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

解题思路:
公主被困了,需要解救,可以有好多个朋友去解救,最近的一个到达公主的房间就算解救成功。遇到士兵可以杀死,但是会额外多增加单位为1的时间。下面给出两种代码,BFS(普通队列)和BFS(优先队列)。截图第一个是BFS(优先队列)

HDU-1242-Rescu

BFS(普通队列)源代码:

BFS(优先队列)源代码:



相关文章:

  • 2021-10-03
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-11-12
  • 2021-08-26
相关资源
相似解决方案