#include<bits/stdc++.h> using namespace std; const int N=1010; int g[N][N]; //存地图 int dist[N][N]; typedef pair<int,int> PII; queue<PII> s; int n,x1,y11,x2,y2=0;
int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1};
int bfs(int x,int y) { memset(dist,-1,sizeof(dist)); s.push({x,y}); dist[x][y]=0; while(!s.empty()) { auto t=s.front(); s.pop(); //第一个再删掉 for(int i=0;i<4;i++) { int a=t.first+dx[i]; int b=t.second+dy[i]; if(a<1 ||a>n || b<1 || b>n) continue; if(dist[a][b]>0) continue; if(g[a][b]!=0) continue; s.push({a,b}); dist[a][b]=dist[t.first][t.second]+1; }
#include<bits/stdc++.h> using namespace std; int n; int g[35][35]; bool st[35][35]; int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0}; typedef pair<int,int> PII; PII q[35*35];
void bfs(int x1,int y1) { q[0]={x1,y1}; int hh=0; int tt=0; while(hh<=tt) { auto t=q[hh++]; //取队头 弹出队头 for(int i=0;i<4;i++) { int a=t.first+dx[i]; int b=t.second+dy[i]; if(g[a][b]==1) continue; if(a<0 || b<0 || a>n+1 || b>n+1 ) continue; if(st[a][b]) continue; st[a][b]=true; q[++tt]={a,b}; } } }
#include<bits/stdc++.h> using namespace std; int m; int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0};
typedef pair<int,int> PII;
#define x first #define y second PII q[310*310]; bool st[310][310]; int dist[310][310]; int fire[310][310]; int bfs(int x1,int y1) { memset(dist,-1,sizeof(dist)); dist[x1][y1]=0; q[0]={x1,y1}; int hh=0,tt=0; while(hh<=tt) { auto t=q[hh++]; for(int i=0;i<4;i++) { int a=t.x+dx[i]; int b=t.y+dy[i]; if(a<0 || b<0 ) continue; if(dist[a][b]>0) continue; if(dist[t.x][t.y]+1>=fire[a][b]) continue; q[++tt]={a,b}; dist[a][b]=dist[t.x][t.y]+1; q[++tt]={a,b}; if(fire[a][b]>1e9) return dist[a][b]; } } return -1; }
int main() { cin>>m; memset(fire,0x3f,sizeof fire); while(m--) { int x2,y2,t; cin>>x2>>y2>>t; fire[x2][y2]=min(t,fire[x2][y2]); for(int i=0;i<4;i++) { int a=x2+dx[i]; int b=y2+dy[i]; if(a<0 || a>301 || b<0 || b>301) continue; fire[a][b]=min(t,fire[a][b]); } } int res=bfs(0,0); cout<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int h[510][510],flag[510][510]; int x3,y3,ans,cnt1,m,n; int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0}; bool st[510][510]; #define x first #define y second
typedef pair<int,int> PII; PII q[510*510];
bool check(int mid1) { //cout<<x1<<" "<<y1<<endl; q[0]={x3,y3}; st[x3][y3]=true; int cnt2=1; //统计经过的路标个数 int hh=0; int tt=0; while(hh<=tt) { auto t=q[hh++]; for(int i=0;i<4;i++) { int a=t.x+dx[i]; int b=t.y+dy[i]; //cout<<t.x<<" "<<t.y<<endl; if(a<1 || a>m || b<1 || b>n) continue; if(abs(h[t.x][t.y]-h[a][b])>mid1) continue; if(st[a][b]==true) continue;