杭电1242---Rescue

Rescue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 19478    Accepted Submission(s): 6939

 Problem Description

Angel was caught by the MOLIGPY! He was putin 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. Theirtask is: approach Angel. We assume that "approach Angel" is to get tothe position where Angel stays. When there's a guard in the grid, we must killhim (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 weare strong enough to kill all the guards.

 You have to calculate the minimal time toapproach Angel. (We can move only UP, DOWN, LEFT and RIGHT, to the neighbor gridwithin bound, of course.)

 Input

First line contains two integers stand forN and M.

 Then N lines follows, every line has Mcharacters. "." 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 shouldoutput a single integer, standing for the minimal time needed. If such a numberdoes no exist, you should output a line containing "Poor ANGEL has to stayin the prison all his life."

Sample Input

7 8

#.#####.

#.a#..r.

#..#x...

..#..#.#

#...##..

.#......

........

Sample Output

13

题意:只是一道简单的BFS问题,遇到卫兵就让时间加1

#include
#include
#include
#include
using namespace std;
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
int n,m;
int vis[205][205];
char mp[205][205];
struct dot
{
    int x,y;
    int time;
};
inline bool in(dot gx)
{
    if(gx.x>=0&&gx.x=0&&gx.y>n>>m)
    {
        dot gx;
        queueq;
        while(!q.empty())
          q.pop();
       memset(vis,0,sizeof(vis));
        for(int i=0;i>mp[i][j];
         for(int i=0;i0)
                    break;

            }
            if(step>0)
                printf("%d\n",step);
            else
                printf("Poor ANGEL has to stay in the prison all his life.\n");
    }
    return 0;
}


 

 


你可能感兴趣的:(搜索)