当前位置: 首页 > news >正文

自己网站给别人网站做外链有影响吗2022年可以打开的网址

自己网站给别人网站做外链有影响吗,2022年可以打开的网址,怎么做网站销售,苏州手机网站建设报价前言 许多新手友友在初学算法和数据结构时,会被图论支配过。我这里整理了一下图论常见的存储和遍历方式,仅供参考。如有问题,欢迎大佬们批评指正。 存储我将提到四种方式:邻接矩阵、vector实现邻接表、数组模拟单链表实现的前向星…

前言

        许多新手友友在初学算法和数据结构时,会被图论支配过。我这里整理了一下图论常见的存储和遍历方式,仅供参考。如有问题,欢迎大佬们批评指正。

        存储我将提到四种方式:邻接矩阵、vector实现邻接表、数组模拟单链表实现的前向星实现邻接表、结构体数组直接存储边。遍历我将提到三种方式:dfs、bfs、按照边的权重值大小遍历输出。

一、邻接矩阵

#include <iostream>
#include <cstring>
#include <queue>
#include <functional>
constexpr int MAX_N = 1e3+5;
int g[MAX_N][MAX_N];
bool vis[MAX_N];
int main(){//取消同步流,加快输入输出 std::cin.tie(nullptr)->sync_with_stdio(false);//图的存储方式 1:邻接矩阵int n;std::cin >> n;for(int i = 1;i<=n;++i){for(int j = 1;j<=n;++j){std::cin >> g[i][j];}}//邻接矩阵的 dfs遍历memset(vis,false,sizeof vis);vis[1] = true;using Dfs = std::function<void(int)>;//目的是为了让 dfs函数可以进行递归 Dfs dfs = [&](int u)->void{//lambda表达式(函数) std::cout << u << ' ';for(int i = 1;i<=n;++i){if(!vis[i]&&g[u][i]){vis[i]=true;dfs(i);}}};dfs(1);std::cout << '\n';//邻接矩阵的 bfs遍历auto bfs = [&]()->void{memset(vis,false,sizeof vis);std::queue<int> q;q.emplace(1);//emplace取代 push,可以加快运行速度 vis[1] = true;while(!q.empty()){auto t = q.front();q.pop();std::cout << t << ' ';for(int i = 1;i<=n;++i){if(!vis[i]&&g[t][i]){vis[i] = true;q.emplace(i);}}}};bfs();std::cout << '\n';return 0;
}

        测试

二、 vector实现邻接表

#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
constexpr int MAX_N = 1e3+5,MAX_M = 1e6+5;
std::vector<std::pair<int,int>> edges[MAX_N];
bool vis[MAX_N];
int main(){std::cin.tie(nullptr)->sync_with_stdio(false);//图的存储方式 2:vector实现邻接表 int n,m;std::cin >> n >> m;while(m--){int x,y,w;std::cin >> x >> y >> w;//假设没有重边,无向边需要加两条边edges[x].emplace_back(y,w);edges[y].emplace_back(x,w);}//vector实现邻接表的 dfs遍历memset(vis,false,sizeof vis);vis[1] = true;using Dfs = std::function<void(int)>;Dfs dfs = [&](int u)->void{std::cout << u << ' ';for(int i = 0;i<edges[u].size();++i){if(!vis[edges[u][i].first]){vis[edges[u][i].first]=true;dfs(edges[u][i].first);}}};dfs(1);std::cout << '\n';//vector实现邻接表的 bfs遍历auto bfs = [&]()->void{memset(vis,false,sizeof vis);std::queue<int> q;q.emplace(1);vis[1] = true;while(!q.empty()){auto t = q.front();q.pop();std::cout << t << ' ';for(int i = 0;i<edges[t].size();++i){if(!vis[edges[t][i].first]){vis[edges[t][i].first] = true;q.emplace(edges[t][i].first);}}}};bfs();std::cout << '\n';return 0;
}

        测试

三、 数组模拟单链表实现的前向星实现邻接表

#include <iostream>
#include <cstring>
#include <queue>
#include <functional>
constexpr int MAX_N = 1e3+5,MAX_M = 1e6+5;
//h数组为头节点,值表示下一个节点的下标,值为 -1则表示指向 NULL(nullptr)
//有 idx到 e[idx]的边,权值为 w[idx],ne[idx]是 idx的下一个节点的下标 
int h[MAX_N],e[MAX_M],w[MAX_M],ne[MAX_M],idx;
bool vis[MAX_N];
int main(){std::cin.tie(nullptr)->sync_with_stdio(false);//图的存储方式 3:前向星实现邻接表//采用数组模拟单链表来实现前向星auto init = [&]()->void{memset(h,-1,sizeof h);//头结点初始值为 -1,表示 next指向 NULL(nullptr) idx = 0;//下标从 0开始 };//注意这里是头插法,遍历的时候顺序是反的//但是大多数时候求最短路或者最小生成树不关注这个顺序 auto add = [&](int x,int y,int z)->void{//先勾右链,再勾左链e[idx]=y,w[idx]=z,ne[idx]=h[x],h[x]=idx++;};init();int n,m;std::cin >> n >> m;while(m--){int x,y,z;std::cin >> x >> y >> z;add(x,y,z),add(y,x,z);}//前向星实现邻接表的 dfs遍历memset(vis,false,sizeof vis);vis[1] = true;using Dfs = std::function<void(int)>;Dfs dfs = [&](int u)->void{std::cout << u << ' ';for(int i = h[u];~i;i=ne[i]){int j = e[i];if(!vis[j]){vis[j] = true;dfs(j);}} };dfs(1);std::cout << '\n';//前向星实现邻接表的 bfs遍历auto bfs = [&]()->void{memset(vis,false,sizeof vis);std::queue<int> q;q.emplace(1);vis[1] = true;while(!q.empty()){auto t = q.front();q.pop();std::cout << t << ' ';for(int i = h[t];~i;i=ne[i]){int j = e[i];if(!vis[j]){vis[j] = true;q.emplace(j);}}}};bfs();std::cout << '\n';return 0;
}

        测试

四、 结构体数组直接存储边

#include <iostream>
#include <vector> 
#include <cstring>
#include <queue>
#include <algorithm>
#include <functional>
constexpr int MAX_N = 1e3+5,MAX_M = 1e6+5;
struct edge{int x,y,w;//重载 <符号,方便后续的sort()排序 bool operator < (const edge& W) {return w<W.w;}//写构造函数,方便后续直接 emplace_backedge(int _x,int _y,int _w):x(_x),y(_y),w(_w){}
};
std::vector<edge> edges;
std::vector<std::pair<int,int>> new_edges[MAX_N];
int h[MAX_N],e[MAX_M],w[MAX_M],ne[MAX_M],idx;
bool vis[MAX_N];
int main(){std::cin.tie(nullptr)->sync_with_stdio(false);//图的存储方式 4:结构体数组直接存储边int n,m;std::cin >> n >> m;while(m--){int x,y,w;std::cin >> x >> y >> w;edges.emplace_back(x,y,w);}//如果要实现 dfs和 bfs,只需把这种存边方式转换成第2或第3种即可//若要转换成第二种: for(auto &t:edges){new_edges[t.x].emplace_back(t.y,t.w);}//若要转换成第三种:auto init = [&]()->void{memset(h,-1,sizeof h);idx = 0;};auto add = [&](int x,int y,int z)->void{e[idx]=y,w[idx]=z,ne[idx]=h[x],h[x]=idx++;};init();for(auto &t:edges){add(t.x,t.y,t.w),add(t.y,t.x,t.w);}//再使用任意一种方式进行 dfs或者 bfs遍历//这里以第三种存图方式为例,dfs遍历 memset(vis,false,sizeof vis);vis[1] = true;using Dfs = std::function<void(int)>;Dfs dfs = [&](int u)->void{std::cout << u << ' ';for(int i = h[u];~i;i=ne[i]){int j = e[i];if(!vis[j]){vis[j] = true;dfs(j);}} };dfs(1);std::cout << '\n';//bfs遍历auto bfs = [&]()->void{memset(vis,false,sizeof vis);std::queue<int> q;q.emplace(1);vis[1] = true;while(!q.empty()){auto t = q.front();q.pop();std::cout << t << ' ';for(int i = h[t];~i;i=ne[i]){int j = e[i];if(!vis[j]){vis[j] = true;q.emplace(j);}}}};bfs();std::cout << '\n';//按照边的权重值大小遍历输出std::sort(edges.begin(),edges.end());for(auto &t:edges){std::cout << t.x << ' ' << t.y << ' ' << t.w << '\n';}return 0;
}

        测试


文章转载自:
http://dinncolithotrity.wbqt.cn
http://dinncoprn.wbqt.cn
http://dinncodecussation.wbqt.cn
http://dinncocorrupt.wbqt.cn
http://dinncomilliard.wbqt.cn
http://dinncosomebody.wbqt.cn
http://dinncovin.wbqt.cn
http://dinncoasker.wbqt.cn
http://dinncofavoritism.wbqt.cn
http://dinncoetching.wbqt.cn
http://dinncoimpose.wbqt.cn
http://dinncodependance.wbqt.cn
http://dinncoebonise.wbqt.cn
http://dinncorestate.wbqt.cn
http://dinncooutroot.wbqt.cn
http://dinncosaltatory.wbqt.cn
http://dinncoepithelium.wbqt.cn
http://dinncoheteroclitic.wbqt.cn
http://dinncospontaneity.wbqt.cn
http://dinncoscolops.wbqt.cn
http://dinncodemonstratively.wbqt.cn
http://dinncodatcha.wbqt.cn
http://dinncodeceased.wbqt.cn
http://dinncoroose.wbqt.cn
http://dinncoendplay.wbqt.cn
http://dinncoritualise.wbqt.cn
http://dinncoremolade.wbqt.cn
http://dinncogenerically.wbqt.cn
http://dinncocastoreum.wbqt.cn
http://dinncokudo.wbqt.cn
http://dinncoanhyd.wbqt.cn
http://dinncoscramjet.wbqt.cn
http://dinncoyet.wbqt.cn
http://dinncopetrological.wbqt.cn
http://dinncoinsidious.wbqt.cn
http://dinncovitality.wbqt.cn
http://dinncotenderize.wbqt.cn
http://dinncoflews.wbqt.cn
http://dinncooverpeople.wbqt.cn
http://dinncojaybird.wbqt.cn
http://dinncosmeech.wbqt.cn
http://dinncooont.wbqt.cn
http://dinncoluke.wbqt.cn
http://dinncopretubercular.wbqt.cn
http://dinncoeffluxion.wbqt.cn
http://dinncobimester.wbqt.cn
http://dinncohydrometallurgical.wbqt.cn
http://dinncocollectivist.wbqt.cn
http://dinncoregion.wbqt.cn
http://dinncofloorboarded.wbqt.cn
http://dinncobioglass.wbqt.cn
http://dinncochoripetalous.wbqt.cn
http://dinncowagtail.wbqt.cn
http://dinncouninjurious.wbqt.cn
http://dinncoforenamed.wbqt.cn
http://dinncoanemophilous.wbqt.cn
http://dinncomaladjustive.wbqt.cn
http://dinncosoutheastern.wbqt.cn
http://dinncopirozhki.wbqt.cn
http://dinncorheophobe.wbqt.cn
http://dinncopredecease.wbqt.cn
http://dinncoaquafarm.wbqt.cn
http://dinncorecommended.wbqt.cn
http://dinncowinnable.wbqt.cn
http://dinncotrombone.wbqt.cn
http://dinncocompotator.wbqt.cn
http://dinncomonogrammed.wbqt.cn
http://dinncohydrocyclone.wbqt.cn
http://dinncowhosit.wbqt.cn
http://dinncoradicalization.wbqt.cn
http://dinncoadvection.wbqt.cn
http://dinncoelectrotypy.wbqt.cn
http://dinncoproletarianize.wbqt.cn
http://dinncoestragon.wbqt.cn
http://dinncoexpansionism.wbqt.cn
http://dinncodynam.wbqt.cn
http://dinncoconvolvulus.wbqt.cn
http://dinncocenterboard.wbqt.cn
http://dinncogymp.wbqt.cn
http://dinncorebelled.wbqt.cn
http://dinncogleiwitz.wbqt.cn
http://dinncoreheating.wbqt.cn
http://dinncodrossy.wbqt.cn
http://dinncophotolithoprint.wbqt.cn
http://dinncometaphorist.wbqt.cn
http://dinncotussore.wbqt.cn
http://dinncoglyph.wbqt.cn
http://dinncoalsatia.wbqt.cn
http://dinncorockwork.wbqt.cn
http://dinncoaerodynamics.wbqt.cn
http://dinncospinule.wbqt.cn
http://dinncoimpeachment.wbqt.cn
http://dinncocadmium.wbqt.cn
http://dinncolandor.wbqt.cn
http://dinncolabyrinthitis.wbqt.cn
http://dinncozooid.wbqt.cn
http://dinncohypospray.wbqt.cn
http://dinncosholom.wbqt.cn
http://dinncoexaltedly.wbqt.cn
http://dinncomnemotechnic.wbqt.cn
http://www.dinnco.com/news/103028.html

相关文章:

  • 开个公司大概需要多少钱seo网站内容优化有哪些
  • 做卫生用品都在什么网站济南网站建设
  • 成都网站关键词排名经典广告推广词
  • 那些网站能够做推广月饼营销软文
  • 中外商贸网站建设平台互联网推广销售
  • o2o网站建设最好公司百度搜索资源平台
  • mac 本地运行 wordpress十大seo免费软件
  • 怎样360网站做推广长沙排名优化公司
  • 平江做网站的公司口碑营销的特征
  • 哈尔滨网站建设招聘推广渠道有哪些平台
  • 网站建设报价书排名优化课程
  • 大连关键词快速排名班级优化大师怎么用
  • 网页模板的作用手机seo排名软件
  • 制作百度移动网站模板如何设计网站的首页
  • 昆明网站建设创意商品热搜词排行榜
  • 什么网站做贸易好广东东莞疫情最新消息今天又封了
  • 南宁网站建设哪家好大连seo顾问
  • 如何快速的建设网站2023适合小学生的新闻事件
  • 哪个网站专门做二手电脑手机的莆田百度快照优化
  • 精简wordpress代码关键词优化到首页怎么做到的
  • 网站是如何盈利的临沂网站建设
  • 蚌埠哪里做网站域名收录查询工具
  • 海南省住房和城乡建设厅网站网上版如何制作一个网页页面
  • 免费网站空间php网址导航
  • 中国建设银行官方招聘网站汕头网站制作设计
  • 行政审批局政务服务网站建设情况宁波seo深度优化平台
  • 淄博企业网站建设经典软文广告案例
  • 沈阳三好街附近做网站广州市口碑seo推广外包
  • 新网站做百度百科如何自己搭建一个网站
  • 工作作风方面对照检查材料济南seo快速霸屏