测试点一自己测试是过的结果全wa,求大犇看看

P1746 离开中山路

Ryoo @ 2024-05-30 18:00:38

#include <bits/stdc++.h>
using namespace std;
int n,x1,x2,y2,dirx[4] = {0,1,0,-1}, diry[4] = {1,0,-1,0},b[1005][1005];
int y11;
char a[1005][1005];
struct bfs{
    int x,y,s;
}h[1000005];
int main() {
    memset(a,'0',sizeof(a));
    memset(b,-1,sizeof(b));
    scanf("%d", &n);
    getchar();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            scanf("%c", &a[i][j]);
            if(a[i][j] == '1') b[i][j] = 0;
        }
        getchar();
    }
    scanf("%d%d%d%d", &x1,&y11,&x2,&y2);
    int head = 0, tail = 1;
    h[1].s = 0;h[1].x = x1;h[1].y = y11;
    while(head <tail) {
        head++;
        for(int i = 0; i <= 3; i++) {
            int xi = h[head].x+dirx[i], yi = h[head].y+diry[i];

            if(xi >= 1 && xi <= n && yi >= 1 && yi <= n && b[yi][xi] == -1) {
                tail++;
                h[tail].s = h[head].s+1;
                h[tail].x = xi;h[tail].y = yi;
                b[yi][xi] = 0;
                if(xi == x2 && yi == y2) {
                    printf("%d", h[tail].s);
                    return 0;
                }
            }
        }
    }
}

|