maoboxiA2 @ 2024-12-14 15:35:36
#include<bits/stdc++.h>
using namespace std;
int n;
char g[1001][1001];
int vis[1001][1001];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int x1,x2,y1,y2;
int ans=0;
struct node{
int x,y,step;
};
queue<node> q;
void bfs(int x,int y,int step){
q.push({x,y,step});
vis[x][y]=1;
while(q.size()){
node t=q.front();
q.pop();
if(t.x==x2&&t.y==y2){
ans=max(ans,t.step);
return;
}
for(int i=0;i<4;i++){
int xx=dx[i]+t.x;
int yy=dy[i]+t.y;
if(xx>=1&&xx<=n&&yy>=1&&yy<=n&&vis[xx][yy]==0&&g[xx][yy]=='0'){
vis[xx][yy]=1;
q.push({xx,yy,t.step+1});
}
}
}
return;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>g[i][j];
}
}
cin>>x1>>y1>>x2>>y2;
bfs(x1,y1,0);
cout<<ans;
return 0;
}
by wangjiawen @ 2024-12-14 15:42:58
@maoboxiA2经典y1
by maoboxiA2 @ 2024-12-14 15:43:39
ok