AVLw @ 2023-11-27 12:29:39
自己弄不明白了 回关注 感谢
#include <iostream>
#include <cstdio>
#include<cstring>
using namespace std;
const int N=444;
int g[N][N],lim[N][N];
int dx[5]={0,0,0,-1,1};
int dy[5]={0,-1,1,0,0};
bool vis[N][N];
struct P{
int x,y,t;
};
P q[N];
int main() {
int m;
cin>>m;
memset(lim,0x3f,sizeof(lim));
for(int i=0;i<m;i++){
int x,y,t;
cin>>x>>y>>t;
for(int j=0;j<5;j++){
int nx=x+dx[j];
int ny=y+dy[j];
if(nx>=0&&ny>=0){
lim[nx][ny]=min(t,lim[nx][ny]);
}
}
}
int l=0,r=0;
q[r++]={0,0,0};
vis[0][0]=true;
while(l<r){
auto cur=q[l++];
int x=cur.x;
int y=cur.y;
int t=cur.t;
if(lim[x][y]==0x3f3f3f){
cout<<t;
return 0;
}
for(int i=0;i<5;i++){
int nx=x+dx[i];
int ny=y+dy[i];
int nt=t+1;
if(nx>=0&&ny>=0&&nt<lim[nx][ny]&&!vis[nx][ny]){
vis[nx][ny]=true;
q[r++]={nx,ny,nt};
cout<<nx<<" "<<ny<<endl;
}
}
}
cout<<-1;
return 0;
}
by AVLw @ 2023-11-27 12:42:07
cout<<nx<<" "<<ny<<endl; 不要在意这句 这是我调试的时候用的
by zrj6666 @ 2023-11-27 15:00:29
@AVLw
while里面的if(lim[x][y] == 0x3f3f3f3f)
by AVLw @ 2023-11-27 16:44:05
@zrj6666 感谢 关注了