14wa求助啊啊啊啊去啊

P2895 [USACO08FEB] Meteor Shower S

qqjddw @ 2024-03-04 18:28:48

93分,14wa,有无大佬帮忙看一下。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

typedef pair<int, int> PII; 

const int N = 310;

struct Node
{
    int x, y, t;
};
int m, res;
int t[N][N];
bool st[N][N];
int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1};

int bfs()
{
    queue<Node> q;
    st[0][0] = true;
    q.push({0, 0, 0});

    while(q.size())
    {
        auto tt = q.front();
        q.pop();
        int x = tt.x, y = tt.y, res = tt.t;

        if(t[x][y] == 1e9) return res;
        for(int i = 0; i < 5; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx <= 300 && ny >= 0 && ny <= 300 && res + 1 < t[nx][ny] && !st[nx][ny])
            {
                st[nx][ny] = true;
                q.push({nx, ny, res + 1});  
            }   
        }
    }

    return -1;
}

int main()
{
    memset(t, 0x3f, sizeof t);
    scanf("%d", &m);
    for(int i = 1; i <= m; i++) 
    {
        int mx, my, mt;
        scanf("%d%d%d", &mx, &my, &mt);
        t[mx][my] = min(t[mx][my], mt);
        if(mx - 1 >= 0) t[mx - 1][my] = min(t[mx - 1][my], mt);
        t[mx + 1][my] = min(t[mx + 1][my], mt);
        if(my - 1 >= 0) t[mx][my - 1] = min(t[mx][my - 1], mt);
        t[mx][my + 1] = min(t[mx][my + 1], mt); 
    }

    cout << bfs() << endl;

    return 0;   
}

by qqjddw @ 2024-03-04 18:30:16

已经自行解决nx,ny无需判断,感谢各位


by aguang666 @ 2024-03-21 22:00:11

@qqjddw 大佬问题是啥呢,我看不出来


by qqjddw @ 2024-03-22 15:57:06

@aguang666 时间太久有点忘了,貌似是不要加nx<=30 && ny <= 300,因为这个人可以跑到横纵坐标300以外的点


by uniquealuo @ 2024-03-23 15:55:22

@qqjddw 哈哈哈,我也是14wa,没想到他可以跑到外面,感谢大佬orz


by aguang666 @ 2024-03-24 09:09:41

@qqjddw 是的,感谢大佬


|