版本比较
2.3 上午 【广搜进阶1】
正文
增加 8 行删除 8 行
105 行未改动全部展开10610710810911011011111211311311411511611711 行未改动12913013113213313313413513613721 行未改动15916016116216316316416516616724 行未改动19219319419519619619719819920020120120220320420549 行未改动25525625725825925926026126226396 行未改动36036136236336436436536636736816 行未改动105 行未改动全部展开int main(){ cin>>n>>m>>sx>>sy; bfs();
for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) for(int j=1;j<=m;j++) { if((i==sx&&j==sy)) { cout<<dist[i][j]<<" ";11 行未改动 return 0;}```## P1332 血色先锋队### 思路:也是bfs,在结构体里面增加t,每次遍历在ans数组里增加1,最后输出ans数组即可;### 思路:这类题是bfs多元点,数组要同时扩散,不同点是在结构体里面增加t,每次遍历在ans数组里增加1,最后输出ans数组即可;```cpp#include <bits/stdc++.h>using namespace std;int n,m,a,b,gx,gy,lx,ly,num=0;21 行未改动 { int x=u.x+dx[i]; int y=u.y+dy[i]; int t=u.t+1;
if(check(x,y)&&!vis[x][y]) { vis[x][y]=1; ans[x][y]=t;24 行未改动 { cin >> lx>> ly; cout<<ans[lx][ly]<<endl; }
return 0;}```## P6207 [USACO06OCT] Cows on Skates G### 思路:bfs,但要加write函数,函数内用递归的形式输出所有可能。### 思路:bfs,pre数组代表记录每一步的x,y,好让输出更方便,还要加write函数,函数内用递归的形式输出所有可能。```cpp#include <bits/stdc++.h>using namespace std;const int maxn = 155;49 行未改动 dis[xx][yy] = dis[u.x][u.y] + 1; pre[xx][yy] = {u.x, u.y}; } }
}}int main(){96 行未改动 } } cout << "KAKTUS";}int main() int main(){ cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) {16 行未改动