Janguiham0319 @ 2025-01-10 14:59:41
#include<bits/stdc++.h>
using namespace std;
#define maxn 301
struct coord{
int x,y;
}
queue<coord>Q;
int ans[maxn][maxn],death[maxn][maxn];
int walk[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int main(){
int m,x,y,t,ANS=1e5;
memset(ans,-1,sizeof(ans));
memset(death,0x7f,sizeof(death));
cin>>m;
for(int i=1;i<=m;i++){
cin>>x>>y>>t;
#define MIN(x,y,t) if(x>=0&&y>=0) death[x][y]=min(death[x][y],t);
MIN(x,y,t);
for(int k=0;k<4;k++){
MIN(x+walk[k][0],y+walk[k][1],t);
}
}
Q.push((coord){0,0});
ans[0][0]=0;
while(!Q.empty()){
coord u=Q.front;
int ux=u.x,uy=u.y;
Q.pop();
for(int k=0;k<4;k++){
int x=ux+walk[k][0],y=uy+walk[k][1];
if(x>=0||y>=0||death[x][y]>=death[ux][uy]+1){
continue;
}
ans[x][y]=ans[ux][uy]+1;
Q.push((coord){x,y});
}
}
for(int i=0;i<=300;i++){
for(int j=0;j<=300;j++){
if(death[i][j]>1000&&ans[i][j]!=-1){
ANS=min(ANS,ans[i][j]);
}
}
}
if(ANS!=1e5) cout<<ANS;
else cout<<"-1";
return 0;
}
by syt_cout @ 2025-01-10 15:09:53
@Janguiham0319Line 6结构体定义后应该加分号; Line 26 调用front时没加括号。