代码过不去样例...求助
查看原帖
代码过不去样例...求助
320697
AMIRIOX無暝楼主2020/8/6 19:11

RT, 代码看了一遍深基的代码打的 结果过不去样例 对书上代码也查不出错 呜呜

#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct pos {
    int x, y;
};
int min(int a, int b) { return a > b ? b : a; }
int pod[1000][1000], rect[1000][1000];
int mov[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
queue<pos> Q;
int main() {
    int m, res = 100000;
    memset(rect, -1, sizeof rect);
    memset(pod, 0x7fffffff, sizeof pod);
    cin >> m;
    for (int i = 1; i <= m; i++) {
        int x, y, t;
        cin >> x >> y >> t;
        #define REC(x, y, t) \
            if (x >= 0 && y >= 0) pod[x][y] = min(pod[x][y], t);
        REC(x, y, t);
        for (int i = 0; i < 4; i++) {
            REC(x + mov[i][0], y + mov[i][1], t);
        }
    }
    Q.push((pos){0, 0});
    rect[0][0] = 0;
    while (!Q.empty()) {
        pos p = Q.front();
        Q.pop();
        int curx = p.x, cury = p.y;
        for (int i = 0; i < 4; i++) {
            int ux = curx + mov[i][0], uy = cury + mov[i][1];
            if (ux < 0 || uy < 0 || rect[ux][uy] != -1 ||
                pod[ux][uy] <= rect[curx][cury] + 1)
                continue;
            rect[ux][uy] = rect[curx][cury] + 1;
            Q.push((pos){ux, uy});
        }
    }
    for (int i = 0; i <= 350; i++) {
        for (int j = 0; j <= 350; j++) {
            if (pod[i][j] > 1000 && rect[i][j] != -1)
                res = min(res, rect[i][j]);
        }
    }
    cout << (res == 100000) ? -1 : res;
    return 0;
}

只是改了一些变量名啥的 ux uy那个变量我仔细对过了

2020/8/6 19:11
加载中...