杭电-2612 Find a way(广搜)

Find a way

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10420    Accepted Submission(s): 3415


Problem Description
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
Yifenfei’s home is at the countryside, but Merceki’s home is in the center of city. So yifenfei made arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they want to choose one that let the total time to it be most smallest.
Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes.
 

Input
The input contains multiple test cases.
Each test case include, first two integers n, m. (2<=n,m<=200).
Next n lines, each line included m character.
‘Y’ express yifenfei initial position.
‘M’    express Merceki initial position.
‘#’ forbid road;
‘.’ Road.
‘@’ KCF
 

Output
For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
 

Sample Input

4 4 Y.#@ .... .#.. @..M 4 4 Y.#@ .... .#.. @#.M 5 5 Y..@. .#... .#... @..M. #...#
 

Sample Output

66 88 66
 

Author
yifenfei
 

Source
奋斗的年代
 

Recommend
yifenfei   |   We have carefully selected several similar problems for you:   1254  1728  2102  1072  1175 

#include
#include
#include
#include
#define MAX 210
#define INF 0x3f3f3f
using namespace std;
int bu1[MAX][MAX];//记录第一个人步数
int bu2[MAX][MAX];//记录第二个人步数
int p;
char map[MAX][MAX];
int vis[MAX][MAX];
int n,m;
struct node
{
    int x,y;
    int step;
};
int MIN(int x,int y)
{
    return xq;
    node beg,end;
    beg.x=x1;
    beg.y=y1;
    beg.step=0;
    q.push(beg);
    while(!q.empty())
    {
        end=q.front();
        q.pop();
        if(map[end.x][end.y]=='@')//遇见@则表示到达终点
        {
            if(p==1)
            bu1[end.x][end.y]=end.step;
            else
            bu2[end.x][end.y]=end.step;
        }
        for(i=0;i<4;i++)
        {
            beg.x=end.x+move[i][0];
            beg.y=end.y+move[i][1];
            if(!vis[beg.x][beg.y]&&0<=beg.x&&beg.x


你可能感兴趣的:(OJ练习)