ZOJ 1649 Rescue(BFS)

基础BFS
#include
#include
#include
#include
#include
using namespace std;
const int maxm=205;
const int inf=1<<29;
int m,n;
int x1,y1,x2,y2;
char map[maxm][maxm];
int vis[maxm][maxm];
int w[maxm][maxm];
int dir[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
struct node
{
    int x;
    int y;
    int step;
    int time;
    bool operator <(const node s)const
    {
        return time>s.time;
    }
};
void bfs()
{
    struct node now,pre;
    priority_queueq;
    pre.x=x1;
    pre.y=y1;
    pre.step=0;
    pre.time=0;
    q.push(pre);
    while(!q.empty())
    {
        pre=q.top();
        q.pop();
        for(int i=0; i<4; i++)
        {
            now.x=pre.x+dir[i][0];
            now.y=pre.y+dir[i][1];
            now.step=pre.step+1;
            now.time=pre.time+1;
            if(now.x>=0&&now.x=0&&now.ynow.time)
                {
                    w[now.x][now.y]=now.time;
                    q.push(now);
                }
            }
        }
    }
    return;
}
int main()
{
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        for(int i=0; i

你可能感兴趣的:(ZOJ,简单搜索,图论)