Beyond_Problem @ 2021-05-31 20:38:19
RT
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAXV 1010
using namespace std;
//rt
int n;
int x1, y1, x2, y2;
bool mapper[ MAXV] [ MAXV];
//bfs
struct zb
{
int x, y;
int jl;
} queue [ 10001100];
int l, r;
int dx [ 5] = { 0, 1, -1, 0, 0}, dy [ 5] = { 0, 0, 0, 1, -1};
//main
int main ( )
{
//sr
cin>> n;
for ( int i = 1; i <= n; i ++)
{
string a;
cin>> a;
for ( int j = 1; j <= n; j ++)
{
if ( a [ j] == '1')
{
mapper [ i] [ j] = 1;
}
else
{
mapper [ i] [ j] = 0;
}
}
}
cin>> x1>> x2>> y1>> y2;
//bfs
l = 1;r = 2;
queue [ 1] = { x1, x2, 0};
mapper [ x1] [ x2] = 1;
while ( l < r)
{
zb now = queue [ l];
l ++;
if ( now. x == x2 && now. y == y2)
{
printf ( "%d\n", now. jl);
return 0;
}
for ( int i = 1; i <= 4; i ++)
{
if ( ! mapper [ dx [ i] + now. x] [ dy [ i] + now. y])
{
mapper [ dx [ i] + now. x] [ dy [ i] + now. y] = 1;
queue [ r ++] = { dx [ i] + now. x, dy [ i] + now. y, now. jl + 1};
}
}
}
}