当前位置: 首页> 文旅> 美景 > 网络设计方案毕业论文_青岛模板做网站_迅雷磁力链bt磁力天堂_小说关键词搜索器

网络设计方案毕业论文_青岛模板做网站_迅雷磁力链bt磁力天堂_小说关键词搜索器

时间:2025/8/26 12:52:19来源:https://blog.csdn.net/jcc_newjourney/article/details/145989972 浏览次数:0次
网络设计方案毕业论文_青岛模板做网站_迅雷磁力链bt磁力天堂_小说关键词搜索器

98. 所有可达路径// DFS

#include <bits/stdc++.h>
using namespace std;vector<vector<int>> result;
vector<int> path;void dfs(const vector<list<int>> &graph, int i, int target) {if (i == target) {result.push_back(path);return;}for (int nums : graph[i]) {path.push_back(nums);dfs(graph, nums, target);path.pop_back();}
}int main() {int n, m;cin >> n >> m;vector<list<int>> graph(n + 1);int temp, next;for (int i = 0; i < m; i++) {cin >> temp >> next;graph[temp].push_back(next);}path.push_back(1);dfs(graph, 1, n);if (result.size() == 0)cout<<-1<<endl;for (int i = 0; i < result.size(); i++) {for (int j = 0; j < result[i].size() - 1; j++) {cout << result[i][j] << " ";}cout << result[i][result[i].size() - 1] << endl;}
}

99. 岛屿数量//。。感觉这题没必要拘泥于用什么搜索。。

#include<bits/stdc++.h>
using namespace std;void DFSfindsameIsland(vector<vector<bool>>& finded,const vector<vector<int>>& graph,int a,int b){if(a<0||b<0||a>graph.size()-1||b>graph[a].size()-1) return;else if(graph[a][b]==0) return;else if(graph[a][b]==1){if(finded[a][b]==false){finded[a][b]=true;DFSfindsameIsland(finded,graph,a,b+1);DFSfindsameIsland(finded,graph,a+1,b);DFSfindsameIsland(finded,graph,a,b-1);DFSfindsameIsland(finded,graph,a-1,b); }else return;}
}
int main(){int i,j;cin>>i>>j;vector<vector<int>> graph(i,vector<int> (j));for(int a=0;a<i;a++){for(int b=0;b<j;b++){cin>>graph[a][b];}}vector<vector<bool>> finded(i,vector<bool> (j,false));int result=0;for(int a=0;a<i;a++){for(int b=0;b<j;b++){if(graph[a][b]==1&&!finded[a][b]){result++;DFSfindsameIsland(finded,graph,a,b);}  }}cout<<result<<endl;     
}

100. 岛屿的最大面积//偷懒了。随便拿上一题的代码改改就交了

#include<bits/stdc++.h>
using namespace std;int DFSfindsameIsland(vector<vector<bool>>& finded,const vector<vector<int>>& graph,int a,int b){if(a<0||b<0||a>graph.size()-1||b>graph[a].size()-1) return 0;else if(graph[a][b]==0) return 0;else{if(finded[a][b]==false){int result=1;finded[a][b]=true;result+=DFSfindsameIsland(finded,graph,a,b+1);result+=DFSfindsameIsland(finded,graph,a+1,b);result+=DFSfindsameIsland(finded,graph,a,b-1);result+=DFSfindsameIsland(finded,graph,a-1,b);return result;}else return 0;}
}
int main(){int i,j;cin>>i>>j;vector<vector<int>> graph(i,vector<int> (j));for(int a=0;a<i;a++){for(int b=0;b<j;b++){cin>>graph[a][b];}}vector<vector<bool>> finded(i,vector<bool> (j,false));int result=0;int maxaera=0;for(int a=0;a<i;a++){for(int b=0;b<j;b++){if(graph[a][b]==1&&!finded[a][b]){maxaera=max(maxaera,DFSfindsameIsland(finded,graph,a,b));}  }}cout<<maxaera<<endl;     
}

关键字:网络设计方案毕业论文_青岛模板做网站_迅雷磁力链bt磁力天堂_小说关键词搜索器

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: