求助。。本地没问题提交全re 莫名其妙

P1746 离开中山路

囧雪诺 @ 2020-05-20 18:28:55

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
struct wz{
    int x,y,bu;
}s;
wz add(int x,int y,int b){
    wz p;
    p.x=x;
    p.y=y;
    p.bu=b;
    return p;
}
int main(){
    int n,x1,x2,y1,y2,ans;
    cin>>n;
    int a[n+5][n+5]={1};
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) a[i][j]=getchar()-'0';
        getchar();
    }

    cin>>x1>>y1>>x2>>y2;
    queue<wz> q;
    s.x=x1;
    s.y=y1;
    s.bu=0;
    q.push(s);
    while(!q.empty()){
        wz t1=q.front();
        if(t1.x==x2&&t1.y==y2){
            ans=t1.bu;break;
        }
        if(a[t1.x][t1.y]!=1){
            q.push(add(t1.x+1,t1.y,t1.bu+1));
            q.push(add(t1.x,t1.y+1,t1.bu+1));
            q.push(add(t1.x-1,t1.y,t1.bu+1));
            q.push(add(t1.x,t1.y-1,t1.bu+1));
        }
        q.pop();
    }
    cout<<ans;
}

by Veranda @ 2020-05-20 18:31:32

数组局部变量炸了,看数据范围定成全局变量


by 天命之路 @ 2020-05-20 18:44:47

绝对是这个问题,把 a 换为全局变量


|