最短路总结

· · 个人记录

总结

T1

struct B
{
    int x,y,z;
    bool b;
}
int d=0x1602;
bool e[1602][1602];
char m[1602][1602];
int A(queue<B>a)
{
    memset(e,true,sizeof(e));
    if(m[a.front().x][a.front().y]=='*')
    {
        return 0x1602;
    }
    e[a.front().x][a.front().y]=false;
    while(a.size())
    {
        B k=a.front();
        a.pop();
        if(m[k.x][k.y]=='A')
        {
            for(int i=0;i<4;i++)
            {
                if(k.x+p[i])
                if(E(k.x+p[i],k.y+q[i]))
                {
                    a.push({k.x+p[i],k.y+q[i]});
                }
            }
        }
    }
    return 0x1602;
}
string D()
{
    queue<B>a;
    a.push({1,n,1});
    d=A(a);
    a.pop();
    a.push({1,1,1});
    d=min(A(a),d);
    a.pop();
    a.push({n,1,1});
    d=min(A(a),d);
    if(d==0x1602)
    {
        return "No answer";
    }
    return to_string(d);
}
bfs遇到障碍不去,走两步的=走一步*2,斜着走额外开个位移数组或者选择在不同直线上的方向走2步,聚气分2步走