cubane @ 2022-03-25 21:07:44
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,s1,s2,s3,s4;
int biao[1001][1001];
char arr[1001][1001];
bool mark[1001][1001];
pair<int,int>dui[1001*1001];
int x1[4]={1,-1,0,0};
int y1[4]={0,0,1,-1};
int bfs(pair<int,int>s){
int begin=0,over=0;
dui[begin++]=s;
while(begin>over){
pair<int,int>h=dui[over++];
for(int i=0;i<4;i++){
int x=h.first+x1[i],y=h.second+y1[i];
if(x<1||x>n||y<1||y>n)continue;
if(mark[x][y])continue;
if(arr[x][y]=='1')continue;
biao[x][y]=biao[h.first][h.second]+1;
if(x==s3&&y==s4)return biao[x][y];
mark[x][y]=1;
dui[begin++]=make_pair(x,y);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>arr[i];
cin>>s1>>s2>>s3>>s4;
cout<<bfs(make_pair(s1,s2));
return 0;
}
by PuitungChan @ 2022-03-28 20:24:20
题目点的下标是1到n,你存的图是0到n-1