版本比较
【广搜BFS】图灵P543. 走出迷宫的最短路径 题解
正文
增加 10 行删除 10 行
18 行未改动19202122232423242526272829303132323334353657 行未改动949596979898991001011021021031041051061071081081091101111122 行未改动1151161171181191191201211221235 行未改动12913013113213313313413513513613713813937 行未改动17717817918018118118218318418526 行未改动18 行未改动
### 样例输入数据 1```8 5 1 1 1 1 1 8 51 1 1 1 10 0 0 0 11 1 1 0 11 0 0 0 11 0 0 1 11 0 0 0 11 1 1 0 11 0 0 0 12 1 2 18 4```
输出数据 157 行未改动void bfs(){ que.push(new Node{sx,sy,0,nullptr}); vis[sx][sy] = 0;
while (!que.empty()) { Node *it = que.front(); que.pop();
if (it->x==ex && it->y==ey) { print(it); exit(0); }
for (int i=0; i<4; i++) { int tx = it->x + dis[i][0]; int ty = it->y + dis[i][1];2 行未改动 que.push(new Node{tx,ty,it->step+1,it}); vis[tx][ty] = it->step; } }
}}
signed main()5 行未改动 for (int j=1; j<=m; j++) scanf("%d", &a[i][j]); } scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
bfs();
printf("no way\n"); return 0;}```37 行未改动 cin >> s1 >> s2 >> e1 >> e2; a[s1][s2] = 1; track[++cnt] = (Info){s1,s2,0}; q.push((Info){s1,s2,0,cnt});
while (!q.empty()) { int pos = q.front().cur; for (i=1; i<=4; i++)26 行未改动