zhangQAQ @ 2021-04-25 18:25:05
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
struct biao
{
int x,y;
};
int b[3000][3000];
biao kai,ju;
queue<biao> q;
char a[4000][4000];
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};
int n,x1,y1,x2,y2;
int main()
{
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
cin>>x1>>y1>>x2>>y2;
kai.x=x1;kai.y=y1;
q.push(kai);
while(!q.empty())
{
kai=q.front();
q.pop();
a[kai.x][kai.y]='1';
if(kai.x==x2&&kai.y==y2)
{
cout<<b[kai.x][kai.y];
break;
}
for(int i=0;i<4;i++)
{
int x=kai.x+dx[i],y=kai.y+dy[i];
if(x>n||x<1||y>n||y<1)continue;
if(a[x][y]=='0')
{
ju.x=x;
ju.y=y;
b[x][y]=b[kai.x][kai.y]+1;
q.push(ju);
}
}
}
return 0;
}
by zhangQAQ @ 2021-04-27 17:22:37
求助
by OutsideR_ @ 2021-05-05 16:32:17
没有标记 否则会卡bug 一直兜圈子