题解—Angel was caught by theMOLIGPY!

Problem Description

Angel was caught by theMOLIGPY! 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 theprison.

Angel's friends want to save Angel. Their task is:approach Angel. We assume that "approach Angel" is to get tothe position where Angel stays.
When there's a guard inthe grid, we must kill him (or her?) to move intothe grid. We assume that we moving up, down, right, lefttakes 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. (Wecan move only UP, DOWN, LEFT and RIGHT, to the neighbor grid within bound, ofcourse.)

Input

First line contains two integers stand for N and M.

Then N lines follows, every line has Mcharacters.
"." stands for road, "a" stands for Angel, and "r" stands for each ofAngel's friend.

Processto the end of the file.

Output

For each test case, yourprogram 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 prisonall his life."

Sample Input

7 8
# . # # # # # .
# . a # . . r .
# . . # x . . .
. . # . . # . #
# . . . # # . .
. # . . . . . .
. . . . . . . .
 
  
Sample Output

13

解题思路:

考虑到1-朋友不止一个,小胖子(angel)只有一个,

           2- 守卫也是一条道路,但通过花费的时间要多,

一开始试图用广搜却不知道那个多一个时间点的守卫怎么处理,看到广搜大部分都和优先队列或者什么剪枝联系在一起,就弱弱的换回了深搜,又没有考虑到小胖子人缘挺好,是friendes,非常迅速的卒了,

bug..s :可以从我的注释里面看到我的各种蠢,就不一一赘述了(捂脸。

AC.1

//朋友不只一个,so..倒着搜
//输入字符串不用&
#include
#include
#include
#include
using namespace std;
int n,m,starx,stary,len,minl;
    //dx[]={-1,1,0,0},dy[]={0,0,-1,1};换一种枚举方法就用不到它了
bool mark[201][201];
char a[201][201];
void search(int x,int y,int len)
{
    //cout<<"x="<

你可能感兴趣的:(ACM解题)