萌新求助!

P2895 [USACO08FEB] Meteor Shower S

Pethly_Cat @ 2020-10-07 11:48:59

第 14 测试点 WA ,快要调疯了

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,l,r,minn=2e9,tim[301][301],f[301][301];
int dx[5]={0,-1,0,0,1};
int dy[5]={0,0,-1,1,0};
bool used[301][301];
void make(int x,int y,int t)
{
    for(int i=0;i<=4;i++)
    if(x+dx[i]>=0&&y+dy[i]>=0) tim[x+dx[i]][y+dy[i]]=min(tim[x+dx[i]][y+dy[i]],t);
}
bool check(int x,int y,int sum)
{
    return (x>=0&&x<=l+1&&y>=0&&y<=r+1&&tim[x][y]>sum&&!used[x][y]);
}
void dfs(int x,int y,int sum)
{
    if(sum>=minn||sum>=f[x][y]) return;
    f[x][y]=sum;
    if(tim[x][y]==0x7f7f7f7f){
        minn=min(minn,sum);
        return;
    }
    if(sum>=l*r) return;
    for(int i=1;i<=4;i++){
        if(!check(x+dx[i],y+dy[i],sum+1)) continue;
        used[x][y]=true;
        dfs(x+dx[i],y+dy[i],sum+1);
        used[x][y]=false;
    }
}
int main()
{
    memset(tim,0x7f,sizeof(tim));
    memset(f,0x7f,sizeof(f));
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x,y,t;
        scanf("%d%d%d",&x,&y,&t);
        l=max(l,x);
        r=max(r,y);
        make(x,y,t);
    }
    dfs(0,0,0);
    if(minn==2e9) printf("-1");
    else printf("%d",minn);
    return 0;
}

by Jack2015633 @ 2020-11-03 16:19:28

需要特判一下

x>300,y>300

时的情况


by Jack2015633 @ 2020-11-03 16:20:15

我也是这个点 调了几个小时 吐了


|