版本比较
3.8 bfd-1
正文
增加 21 行删除 21 行
40 行未改动4142434445454647484748495051525353545555565758595758596061626263646566676865666768697071727273747576777778798081808182838484858687878889909191929393949596974 行未改动40 行未改动using namespace std;
const int N = 405;
struct P struct P{ int x, y, st; }; 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]; char mp[N][N];
void bfs() void bfs(){ memset(vis, 0, sizeof vis); queue<P> q; 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 && now.y == m) P now = q.front(); q.pop();
if (now.x == n && 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});
q.push({nx, ny, now.st+1}); vis[nx][ny] = 1; } } }}
int main() int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) for (int j=1; j<=m; j++) { cin >> mp[i][j]; } }4 行未改动