7分求助!!!

P2895 [USACO08FEB] Meteor Shower S

12345xxx @ 2024-08-25 10:45:26

呜呜呜上一篇帖子没人回复,

dalao帮我看看吧!!!

#include<bits/stdc++.h>
using namespace std;
int dx[5]={0,0,-1,0,1};
int dy[5]={0,-1,0,1,0};
int a[305][305];
struct node{
    int x,y;
};
int m;
int k[305][305];
bool b[305][305];
queue<node> q;
int check(int now){
    if(now==-1){
        return 99999;
    }
    else{
        return now;
    }
}
int main(){
    cin>>m;
    for(int i=0;i<=305;i++){
        for(int j=0;j<=305;j++){
            k[i][j]=-1;
        }
    }
    for(int i=1;i<=m;i++){
        int t,x,y;
        cin>>t>>x>>y;
        for(int j=0;j<=4;j++){
            int tmpx=x+dx[j];
            int tmpy=y+dy[j];
            if(tmpx>=0&&tmpy>=0&&(k[tmpx][tmpy]==-1||k[tmpx][tmpy]>t)){
                k[tmpx][tmpy]=t;
            }
        }
    }
    q.push({0,0});
    b[0][0]=1;
    while(!q.empty()){
        node u=q.front();
        q.pop();
        int v=a[u.x][u.y]+1;
        if(k[u.x][u.y]==-1){
            cout<<v-1;
            return 0;
        }
        for(int i=1;i<=4;i++){
            int nx=u.x+dx[i];
            int ny=u.y+dy[i];
            if(nx>=0&&ny>=0&&v<check(k[nx][ny])&&b[nx][ny]==0){
                q.push({nx,ny});
                b[nx][ny]=1;
                a[nx][ny]=v;
            }
        }
    }
    cout<<-1;
    return 0;
}

先谢谢了Orz Orz


by 天南星魔芋 @ 2024-08-25 11:03:09

@12345xxx 数组 k 初始化数组越界

并且读入格式错误


by 12345xxx @ 2024-08-25 11:04:30

@天南星魔芋 感谢,已过,这错有点奇葩


|