q_james_c @ 2021-11-11 17:33:43
#include<bits/stdc++.h>
using namespace std;
int m,s,ans;
int tox[6]={0,0,1,-1};
int toy[6]={1,-1,0,0};
int die[305][305],vis[305][305];
struct po{
int xx,yy,tt;
};
queue<po> q;
int lala(int x,int y){
if(die[x][y]==-1) return 99999;
return die[x][y];
}
int main(){
memset(die,-1,sizeof(die));
cin>>m;
vis[0][0]=1;
for (int i=1,x,y,t;i<=m;++i){
cin>>x>>y>>t;
die[x][y]=t;
for (int i=0;i<=3;++i){
int nx=x+tox[i],ny=y+toy[i];
if(nx>=0&&ny>=0&&(die[nx][ny]==-1||die[nx][ny]>t)) die[nx][ny]=t;
}
}
q.push((po){0,0,0});
while(!q.empty()){
po now=q.front();
q.pop();
if(die[now.xx][now.yy]==-1){
cout<<now.tt;
return 0;
}
for (int i=0;i<=3;++i){
po neww;
neww.xx=now.xx+tox[i];
neww.yy=now.yy+toy[i];
neww.tt=now.tt+1;
if(vis[neww.xx][neww.yy]==0&&neww.xx>=0&&neww.yy>=0&&neww.tt<lala(neww.xx,neww.yy)){
// cout<<"/";
vis[neww.xx][neww.yy]=1;
q.push(neww);
}
}
}
cout<<-1;
return 0;
}
by noctuque @ 2021-11-13 10:55:02
楼主,你的时间判断有问题,lala这个函数并不需要,具体私聊
by q_james_c @ 2021-11-13 10:56:38
多谢dalao答疑解惑