#include <bits/stdc++.h>
using namespace std;
struct qwq {
int x,y;
int v;
};
int f[10] = {1,2,4,8,16,32,64,128,256,512};
int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int n,m;
int h[1145][1145],l[1145][1145];
bool v[1145][1145];
char c[1145][1145];
int DFS() {
queue <qwq> q;
q.push({1,1,0});
v[1][1] = 1;
while (!q.empty()) {
int x = q.front().x,y = q.front().y,val = q.front().v;
q.pop();
if (c[x][y] == '#') return val;
for (int i = 0;i < 4;++i) {
for (int j = 0;j <= 9;++j) {
int nx = x + d[i][0] * f[j],ny = y + d[i][1] * f[j];
if (nx < 1 || nx > n || ny < 1 || ny > m || v[nx][ny]) continue;
if (c[nx][ny] == 'X') break;
if (d[i][0] == 1 && h[nx][ny] - h[x][y]) break;
if (d[i][1] == 1 && l[nx][ny] - l[x][y]) break;
v[nx][ny] = 1;
q.push({nx,ny,val + 1});
}
}
}
return -1;
}
int main() {
cin >> n >> m;
for (int i = 1;i <= n;++i) {
for (int j = 1;j <= m;++j) {
cin >> c[i][j];
if (c[i][j] == 'X') h[i][j] = h[i - 1][j] + 1,l[i][j] = l[i][j - 1] + 1;
else h[i][j] = h[i - 1][j],l[i][j] = l[i][j - 1];
}
}
cout << DFS() ;
}
#8wa
还想问一下26行的break和continue有什么区别