为什么全RE了

P1746 离开中山路

喵喵喵__ @ 2021-05-09 09:48:17

起初以为数组越界

现在判断可能是 getchar() 的问题,但快读不也用 getchar() 吗。

太奇怪了 喵喵喵 不会是个很傻逼的错误吧

/*
全部RE了 很奇怪 不会是洛谷的测评姬炸了吧
*/
#include<cstdio>
#include<cstring>
#include<queue>
#include<stdbool.h>
int read() {
    int r = 0; char ch = getchar();
    while (ch < '0' || ch > '9')ch = getchar();
    while (ch >= '0' && ch <= '9')r = (r << 1) + (r << 3) + (ch ^ 48), ch = getchar();
    return r;
}
int n, dp[1 << 10][1 << 10], x, y, x_end, y_end;
char arr[1<<10][1<<10];
int a[4] = { 1, -1, 0, 0 };
int b[4] = { 0, 0, -1, 1 };
inline bool judge(int x, int y) {
    return arr[x][y] == 0 && dp[x][y] == -1;
}
void bfs(int x, int y, int x_end ,int y_end) {
    memset(dp, -1, sizeof dp);
    std::queue<int> q1, q2;
    q1.push(x); q2.push(y);
    dp[x][y] = 0;
    while (!q1.empty()) {
        int x = q1.front(); q1.pop();
        int y = q2.front(); q2.pop();
        for (int i = 0; i < 4; i++) {
            if (judge(x + a[i], y + b[i])) {
                q1.push(x + a[i]); q2.push(y + b[i]);
                dp[x + a[i]][y + b[i]] = dp[x][y] + 1;
                if (x + a[i] == x_end && y + b[i] == y_end) {
                    printf("%d", dp[x_end][y_end]);
                    return;
                }
            }
        }
    }
}
int main() {
    n = read();//read函数会吃掉末尾的换行
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            arr[i][j] = getchar()^48;
        }
        char ch = getchar();
    }
    for (int i = 0; i <= n + 1; i++) {
         arr[i][0] = arr[0][i] = 1;
         arr[n + 1][i] = arr[i][n + 1] = 1;
    }
    x = read(); y = read();
    x_end = read(); y_end = read();
    bfs(x, y, x_end, y_end);
}

by 庄nnnn额 @ 2021-07-31 22:26:52

应该是没有

return 0;

吧?


|