正文
增加 15 行删除 15 行
34 行未改动35363738394041424344454647484950515253545556575859606162636465666768697071727374757614 行未改动34 行未改动const int N = 45;struct P {int x, y, st; // 这个点的行、列、步数};int n, m;int d[4][2] = {0, 1, 1, 0, -1, 0, 0, -1};int vis[N][N];char mp[N][N];void bfs() {memset(vis, 0, sizeof vis); // 清空标记queue<P> q; // 结构体队列q.push({1, 1, 1});vis[1][1] = 1;while (q.size()) {P now = q.front(); // 取出队首元素q.pop();if (now.x == n and now.y == m) {cout << now.st;return ;}for (int i=0; i<4; i++) {int nx = now.x + d[i][0];int ny = now.y + d[i][1];if (nx < 1 or nx > n or ny < 1 or ny > m) continue;if (mp[nx][ny] == '#' or vis[nx][ny]) continue;q.push({nx, ny, now.st+1}); // 新的点入队,并且表示当前点已经处理过vis[nx][ny] = 1;}}}int main() {ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);14 行未改动34 行未改动35363738394041424344454647484950515253545556575859606162636465666768697071727374757614 行未改动34 行未改动const int N = 45;struct P {int x, y, st; // 这个点的行、列、步数};int n, m;int d[4][2] = {0, 1, 1, 0, -1, 0, 0, -1};int vis[N][N];char mp[N][N];void bfs() {memset(vis, 0, sizeof vis); // 清空标记queue<P> q; // 结构体队列q.push({1, 1, 1});vis[1][1] = 1;while (q.size()) {P now = q.front(); // 取出队首元素q.pop();if (now.x == n and now.y == m) {cout << now.st;return ;}for (int i=0; i<4; i++) {int nx = now.x + d[i][0];int ny = now.y + d[i][1];if (nx < 1 or nx > n or ny < 1 or ny > m) continue;if (mp[nx][ny] == '#' or vis[nx][ny]) continue;q.push({nx, ny, now.st+1}); // 新的点入队,并且表示当前点已经处理过vis[nx][ny] = 1;}}}int main() {ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);14 行未改动