ans
X-jinchen
2022-05-21 15:52:33
23
返回题目
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,d;
};
queue<node>q;
char a[1000+10][1000+10];
int x,y,u,v;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int bfs(int x,int y){
q.push(node{x,y,0});
a[x][y]='1';
while (!q.empty()){
node now=q.front();
q.pop();
for (int i=0;i<4;i++){
int nx=now.x+dx[i];
int ny=now.y+dy[i];
if (a[nx][ny]=='1') continue;
if (nx==u && ny==v) return now.d+1;
q.push(node{nx,ny,now.d+1});
a[nx][ny]='1';
}
}
}
int main(){
int n;
cin>>n;
memset(a,'1',sizeof(a));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
cin>>x>>y>>u>>v;
cout<<bfs(x,y);
return 0;
}
{{ vote && vote.total.up }}
共 2 条回复
呃------------------------
干得漂亮