JiuZhE66666 @ 2023-09-08 08:57:35
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int l[5]={0,-1,1,0,0},r[5]={0,0,0,1,-1};
queue<pair<int,int>> q;
int farm[500][500]={0};
int steps[500][500]={0};
memset(farm,-1,sizeof(farm));
memset(steps,-1,sizeof(steps));
for(int i=1;i<=n;i++)
{
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
for(int j=0;j<5;j++)
{
if(x+l[j]>=0&&y+r[j]>=0)
{
if(farm[x+l[j]][y+r[j]]==-1)farm[x+l[j]][y+r[j]]=t;
else farm[x+l[j]][y+r[j]]=min(farm[x+l[j]][y+r[j]],t);
}
}
}
/* for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)printf("%d ",farm[i][j]);
printf("\n");
}*/
q.push(make_pair(0,0));
int num=1;
steps[0][0]=0;
while(!q.empty())
{
int x1=q.front().first,y1=q.front().second;
q.pop();
for(int j=1;j<5;j++)
{
if(x1+l[j]>=0&&y1+r[j]>=0)
if(farm[x1+l[j]][y1+r[j]]>x1+l[j]+y1+r[j]&&steps[x1+l[j]][y1+r[j]]==-1||farm[x1+l[j]][y1+r[j]]==-1)
{
q.push(make_pair(x1+l[j],y1+r[j]));
steps[x1+l[j]][y1+r[j]]=steps[x1][y1]+1;
}
}
if(farm[x1][y1]==-1)
{
num=0;
printf("%d",steps[x1][y1]);
break;
}
// printf("%d %d\n",x1,y1);
}
if(num==1) printf("-1");
return 0;
}
by JiuZhE66666 @ 2023-09-08 10:40:19
我知道错哪了,到底某一点的时间不是由坐标决定的,而是叠加的