无限死循环,玄关!

P2895 [USACO08FEB] Meteor Shower S

Zivsfamily @ 2024-07-27 19:17:43


#include<bits/stdc++.h>
using namespace std;
const int MAXN=303;
int meteor[MAXN][MAXN];
int m,ans=-1;
int dx[]={0,0,0,-1,1};
int dy[]={0,-1,1,0,0};
void bfs(int x,int y,int t){
    if(meteor[x][y]==1001){
        if(ans==-1){
            ans=t;
        }else{
            ans=min(ans,t);
        }
    }
    for(int i=0;i<=4;i++){
        int xx=x+dx[i];
        int yy=y+dy[i];
        if(xx<0||yy<0||meteor[xx][yy]<t){
            continue;
        }
        bfs(xx,yy,t+1);
    }
}
int main(){
    for(int i=0;i<MAXN;i++){
        for(int j=0;j<MAXN;j++){
            meteor[i][j]=1001;
        }
    }
    scanf("%d",&m);
    int a,b,c;
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&a,&b,&c);
        for(int j=0;j<4;j++){
            meteor[a-dx[j]][b-dy[j]]=min(meteor[a-dx[j]][b-dy[j]],c);
        }
    }
    bfs(0,0,0);
    printf("%d\n",ans);
    return 0;
}

by chenhaoqwq @ 2024-07-27 19:52:02

meteor[a-dx[j]][b-dy[j]]=min(meteor[a-dx[j]][b-dy[j]],c);

这里要判小于0的情况,不然会re


by chenhaoqwq @ 2024-07-27 19:53:41

@Zivsfamily 哥们你这代码错漏百出啊,不用vis的吗


by chenhaoqwq @ 2024-07-27 19:54:14

@Zivsfamily 死循环+re离谱的


|