HDU 1242 Rescue (搜索)水题

题意:求a到r的最短路,,到#时的路的长度为2

#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
int n,m;
const int N = 209;
char map[N][N];
bool visit[N][N];
struct node
{
    int x,y,dis;
    bool operator<(const node t) const
    {
        return dis>t.dis;
    }
} st,en;
int dx[]= {0,0,-1,1};
int dy[]= {-1,1,0,0};
bool oor(int x,int y)
{
    if(x<0||x>=n) return false;
    if(y<0||y>=m) return false;
    return true;
}
int main()
{
    freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=0; i que;
        st.dis =0;
        while(!que.empty()) que.pop();
        memset(visit,false,sizeof(visit));
        que.push(st);
        node e,t;
        bool ou = false;
        while(!que.empty())
        {
            e= que.top();
            que.pop();
            if(e.x==en.x&&e.y==en.y)
            {
                printf("%d\n",e.dis);
                ou = true;
                break;
            }
            if(visit[e.x][e.y]) continue;
            visit[e.x][e.y] = true;
            for(int i=0; i<4; i++)
            {
                int tx = e.x+dx[i],ty = e.y+dy[i];
                if(!oor(tx,ty)||visit[tx][ty]||map[tx][ty]=='#') continue;
                if(map[tx][ty]=='x') t.dis = e.dis+2;
                else t.dis=e.dis+1;
                t.x = tx;
                t.y = ty;
                que.push(t);
            }
        }
        if(!ou)
        printf("Poor ANGEL has to stay in the prison all his life.\n");
    }
    return 0;
}


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