焚魂 @ 2020-02-13 15:22:37
//离开中山路
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long dx[5]={0,0,1,0,-1},
dy[5]={0,1,0,-1,0};
long long head=0,tail=1;
long long sx,sy,ex,ey,n,a[10010],b[10010],pre[10010];
char map[10100][10010];
bool f=0,bb[10010][10010];
int main()
{
cin>>n;
for(long long i=1;i<=n;i++)
for(long long j=1;j<=n;j++)
cin>>map[i][j];
cin>>sx>>sy>>ex>>ey;
f=0;
bb[sx][sy]=1;
a[tail]=sx;
b[tail]=sx;
pre[tail]=0;
while(head!=tail)
{
head++;
for(long long i=1;i<=4;i++)
{
long long x=a[head]+dx[i];
long long y=b[head]+dy[i];
if(x>0 && y>0 && x<=n && y<=n && bb[x][y]!=1 && map[x][y]!='1')
{
tail++;
a[tail]=x;
b[tail]=y;
pre[tail]=head;
bb[x][y]=1;
if(x==ex && y==ey)
{
f=1;
cout<<head;
return 0;
}
}
}
}
return 0;
}
by wwsz_cn @ 2020-02-14 16:21:47
@焚魂
STL里的队列不香吗?