读地图的时候没有空格 无语啦
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1001][1001];
//3
//001
//101
//100
//1 1 3 3
int b[1001][1001] = {0};
struct xy {
int x, y;
};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
queue <xy> q;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%1d", &a[i][j]);
}
}
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
q.push({x1, y1});
while (!q.empty()) {
xy u = q.front();
if (u.x == x2 && u.y == y2)
break;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = u.x + dx[i];
int yy = u.y + dy[i];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= n && a[xx][yy] == 0 && b[xx][yy] == 0) {
q.push({xx, yy});
b[xx][yy] = b[u.x][u.y] + 1;
}
}
}
cout << b[x2][y2];
return 0;
}