版本比较
第一次晚上课程
正文
增加 10 行删除 10 行
39 行未改动4041424344454647484950515234 行未改动8788899091929394959697989910010110210310410535 行未改动14114214314414514614714814915015115215315415515645 行未改动20220320420520620720820921021121221353 行未改动2672682692702712722732742752762772786 行未改动39 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){cin >> a[i][j];}}cin >> sx >> sy >> ex >> ey;bfs();return 0;}```思路:这是一道bfs的板子题。## bfs2```cpp34 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){vis[i][j] = -1;//将初始值设为-1.}}cin >> sx >> sy;bfs();for(int i = 1; i <= n; i++){//输出标记数组for(int j = 1; j <= m; j++){cout << vis[i][j] << " ";}cout << '\n';}return 0;}```思路:这道题和上一道题差不多,只要将上一道题的方向数组改一下,再加一个标记步数的数组即可。## dfs3```cpp35 行未改动for(int i = 1; i <= a; i++){cin >> x >> y;q.push({x, y});//将每个起点都放入队列中,然后一起广搜vis[x][y] = 0;}bfs();for(int i = 1; i <= b; i++){cin >> x >> y;cout << vis[x][y] << '\n';}return 0;}```思路:这道题采用了多源点广搜。## dfs4```cpp45 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}bfs();return 0;}/*5 8..*...***.*.*.**53 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}bfs();return 0;}/*5 8..*...***.*.*.**6 行未改动39 行未改动4041424344454647484950515234 行未改动8788899091929394959697989910010110210310410535 行未改动14114214314414514614714814915015115215315415515645 行未改动20220320420520620720820921021121221353 行未改动2672682692702712722732742752762772786 行未改动39 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){cin >> a[i][j];}}cin >> sx >> sy >> ex >> ey;bfs();return 0;}```思路:这是一道bfs的板子题。## bfs2```cpp34 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){vis[i][j] = -1;//将初始值设为-1.}}cin >> sx >> sy;bfs();for(int i = 1; i <= n; i++){//输出标记数组for(int j = 1; j <= m; j++){cout << vis[i][j] << " ";}cout << '\n';}return 0;}```思路:这道题和上一道题差不多,只要将上一道题的方向数组改一下,再加一个标记步数的数组即可。## dfs3```cpp35 行未改动for(int i = 1; i <= a; i++){cin >> x >> y;q.push({x, y});//将每个起点都放入队列中,然后一起广搜vis[x][y] = 0;}bfs();for(int i = 1; i <= b; i++){cin >> x >> y;cout << vis[x][y] << '\n';}return 0;}```思路:这道题采用了多源点广搜。## dfs4```cpp45 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}bfs();return 0;}/*5 8..*...***.*.*.**53 行未改动for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin >> a[i][j];}}bfs();return 0;}/*5 8..*...***.*.*.**6 行未改动