#include<bits/stdc++.h>
using namespace std;
struct s //结构体用来表示坐标
{
int x;
int y;
};
queue<s> q; //队列用来行走
int d[1999][1999]; //记录步数
bool v[1999][1999]; //标记是否走过
char Map[199][199]; //地图
int N, M, s1, s2, e1, e2; //地图的长,宽,起点坐标&&终点坐标
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; //用来上下左右查找
void vis() //初始化
{
memset(d, 0, sizeof(d));
memset(v, false, sizeof(v));
}
int panduan(int x, int y)
{
if(x >= 0 && x < M && y >= 0 && y < N && !v[x][y] && Map[x][y] == '.') //判断是否越界以及这个坐标是否走过了以及这个坐标是否能走(假设点是路)
return 1;
else
return 0;
}
int bfs()
{
s a;
a.x = s1;
a.y = s2;
q.push(a);
while(!q.empty())
{
q.pop();
a = q.front();
v[a.x][a.y] = 1; //记录 表示这个坐标已经走过了
if(a.x == e1 && a.y == e2)
return d[e1][e2];
for(int i = 0; i < 4; i++) //用来上下左右四个方向查找
{
s n;
n.x = a.x + dx[i];
n.y = a.y + dy[i];
if(panduan(n.x, n.y))
{
d[n.x][n.y] = d[a.x][a.y] + 1; //步数在原来的基础上加一
v[n.x][n.y] = 1; //标记 证明这个坐标走过了
q.push(n); //把这个点压入队列
}
}
}
}
int main()
{
// 输入地图的厂,宽,起点坐标和终点坐标
vis();
cout << bfs() << endl;
return 0;
}
using namespace std;
struct s //结构体用来表示坐标
{
int x;
int y;
};
queue<s> q; //队列用来行走
int d[1999][1999]; //记录步数
bool v[1999][1999]; //标记是否走过
char Map[199][199]; //地图
int N, M, s1, s2, e1, e2; //地图的长,宽,起点坐标&&终点坐标
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; //用来上下左右查找
void vis() //初始化
{
memset(d, 0, sizeof(d));
memset(v, false, sizeof(v));
}
int panduan(int x, int y)
{
if(x >= 0 && x < M && y >= 0 && y < N && !v[x][y] && Map[x][y] == '.') //判断是否越界以及这个坐标是否走过了以及这个坐标是否能走(假设点是路)
return 1;
else
return 0;
}
int bfs()
{
s a;
a.x = s1;
a.y = s2;
q.push(a);
while(!q.empty())
{
q.pop();
a = q.front();
v[a.x][a.y] = 1; //记录 表示这个坐标已经走过了
if(a.x == e1 && a.y == e2)
return d[e1][e2];
for(int i = 0; i < 4; i++) //用来上下左右四个方向查找
{
s n;
n.x = a.x + dx[i];
n.y = a.y + dy[i];
if(panduan(n.x, n.y))
{
d[n.x][n.y] = d[a.x][a.y] + 1; //步数在原来的基础上加一
v[n.x][n.y] = 1; //标记 证明这个坐标走过了
q.push(n); //把这个点压入队列
}
}
}
}
int main()
{
// 输入地图的厂,宽,起点坐标和终点坐标
vis();
cout << bfs() << endl;
return 0;
}