再改我人RE了

P1746 离开中山路

130gzl @ 2024-07-18 12:15:49

#include <bits/stdc++.h>
using namespace std;
struct node{int x,y,cnt=0;};
queue<node> q;
int a[1024][1024],n;
node r0,r1,now,p;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        string in;
        cin>>in;
        for(int j=0;j<n;j++){
            char ic;
            ic=in[i];
            int iic=(int)(ic-48);
            a[i][j]=iic;
        }
    }
    cin>>r0.x>>r0.y>>r1.x>>r1.y;
    //cout<<"-----------------"<<endl;
    q.push(r0);
    while(!q.empty()){
        now=q.front();q.pop();
        int x=now.x,y=now.y;
        if(now.x==r1.x&&now.y==r1.y){
            cout<<now.cnt;
            return 0;
        }
        p.x=-1;
        if(x+1<n&&y<n&&!a[x+1][y])p.x=x+1,p.y=y,p.cnt=now.cnt+1;
        if(p.x>=0){q.push(p);/*cout<<p.x+1<<" "<<p.y+1<<endl;*/}

        p.x=-1;
        if(x<n&&y+1<n&&!a[x][y+1])p.x=x+1,p.y=y,p.cnt=now.cnt+1;
        if(p.x>=0){q.push(p);/*cout<<p.x+1<<" "<<p.y+1<<endl;*/}
        //cout<<"-----"<<q.size()<<endl;
    }
    return 0;
}

|