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

创意礼品做的比较好的网站网络推广和seo

创意礼品做的比较好的网站,网络推广和seo,做网站需要的资料,汕头澄海天气预报Prim算法: 算法步骤: 1.选择一个起始节点作为最小生成树的起点。 2.将该起始节点加入最小生成树集合,并将其标记为已访问。 3.在所有与最小生成树集合相邻的边中,选择权重最小的边和它连接的未访问节点。 4.将该边和节点加入最小…

Prim算法:

算法步骤:
1.选择一个起始节点作为最小生成树的起点。
2.将该起始节点加入最小生成树集合,并将其标记为已访问。
3.在所有与最小生成树集合相邻的边中,选择权重最小的边和它连接的未访问节点。
4.将该边和节点加入最小生成树集合,并将该节点标记为已访问。
重复步骤3和步骤4,直到最小生成树集合包含了图中的所有节点。

#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;int n;
int wei[101][101];
bool visit[101];int prim()
{int res = 0;//总共加n-1条边for (int k = 0; k < n - 1; k++){int mi = 999999;int idex;//先把节点1加入,所以是从2开始遍历for (int i = 2; i <= n; i++){if (visit[i] == 1){continue;}//找到当前已经加入的集合到其余节点的最小边的距离if (mi > wei[1][i]){mi = wei[1][i];idex = i;}}visit[idex] = 1;res += wei[1][idex];for (int i = 2; i <= n; i++){//更新当前已经加入的集合到其余节点的最小边的距离,统一以1为标记点。//新加入的为index,所以对index往外的每条边都要判断是否需要更新if (wei[idex][i] < wei[1][i]){wei[1][i] = wei[idex][i];}}}return res;
}int main()
{cin >> n;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){cin >> wei[i][j];}}cout << prim();
}
堆优化Prim算法:

算法步骤
初始化dist 数组为INF,表示所有节点到集合的距离为无穷大。
创建一个小根堆,堆中的元素为(dist 值, 节点编号)。
堆中先插入 ( 0 , 1 )  表示节点1进入集合, dist 值为 0。
每次从堆中取出 dist 值最小的元素 (d,u),将u加入集合。
对 u 相邻的所有节点 v,更新 dist[v]=min(dist[v],g[u][v]),并更新堆中的相应元素。
重复步骤 4、5,直到所有节点都加入集合。
最后根据取出的 dist 值之和求得最小生成树权重。

#define _CRT_SECURE_NO_WARNINGS#include<iostream>
#include<cstring>
#include<vector>
#include<queue>using namespace std;const int N = 510, M = 1e5 + 10;
typedef pair<int, int> PII;
bool st[N]; // 标记节点是否已经加入最小生成树
int n, m, dist[N]; // dist数组用于记录每个节点到最小生成树的距离
int h[N], e[M], ne[M], idx, w[M]; // 邻接表存储图的边信息void add(int a, int b, int c)
{e[idx] = b; // 存储边的另一个节点w[idx] = c; // 存储边的权值ne[idx] = h[a]; // 将边插入到节点a的邻接表头部h[a] = idx++; // 更新节点a的邻接表头指针
}int Prim()
{int res = 0, cnt = 0; // res用于记录最小生成树的权值和,cnt用于记录已经选择的边数priority_queue<PII, vector<PII>, greater<PII>> heap; // 最小堆,用于选择最短边memset(dist, 0x3f, sizeof dist); // 初始化dist数组为无穷大heap.push({ 0, 1 }); // 将节点1加入最小堆,距离为0dist[1] = 0; // 节点1到最小生成树的距离为0while (heap.size()){auto t = heap.top(); // 取出最小堆中距离最小的节点heap.pop();int ver = t.second, destination = t.first; // ver为节点,destination为距离if (st[ver]) continue; // 如果节点已经在最小生成树中,跳过st[ver] = true; // 将节点标记为已经加入最小生成树res += destination; // 更新最小生成树的权值和cnt++; // 增加已选择的边数// 遍历节点ver的所有邻接边for (int i = h[ver]; i != -1; i = ne[i]){auto u = e[i]; // 邻接边的另一个节点if (dist[u] > w[i]){dist[u] = w[i]; // 更新节点u到最小生成树的距离heap.push({ dist[u], u }); // 将节点u加入最小堆}}}// 如果最小生成树的边数小于n-1,则图不连通,返回0x3f3f3f3f表示不可达if (cnt < n) return 0x3f3f3f3f;return res; // 返回最小生成树的权值和
}int main()
{cin.tie(0);ios::sync_with_stdio(false);memset(h, -1, sizeof h); // 初始化邻接表头指针为-1cin >> n >> m; // 输入节点数和边数for (int i = 0; i < m; ++i){int a, b, c;cin >> a >> b >> c;add(a, b, c), add(b, a, c); // 添加无向图的边到邻接表中}int t = Prim(); // 计算最小生成树的权值和if (t == 0x3f3f3f3f)cout << "impossible" << endl; // 输出不可达elsecout << t << endl; // 输出最小生成树的权值和return 0;
}

Kruskal算法:

使用结构体存图,结构体中存放点,点,以及这两个点之间边的长度。

首先将结构体排序,按照边的大小从小到大排序。

然后按照边从小到大的顺序依次加入集合。若发现当前边已经在集合中了则跳过。

	// Kruskal 算法求最小生成树 #include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 2e5 + 10; struct node {int x,y,z;}edge[maxn];bool cmp(node a,node b) {return a.z < b.z;}int fa[maxn];int n,m;int u,v,w; long long sum;int get(int x) {return x == fa[x] ? x : fa[x] = get(fa[x]);}int main(void) {scanf("%d%d",&n,&m);for(int i = 1; i <= m; i ++) {scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].z);}for(int i = 0; i <= n; i ++) {fa[i] = i;}sort(edge + 1,edge + 1 + m,cmp);// 每次加入一条最短的边for(int i = 1; i <= m; i ++) {int x = get(edge[i].x);int y = get(edge[i].y);if(x == y) continue;fa[y] = x;sum += edge[i].z;}int ans = 0;for(int i = 1; i <= n; i ++) {if(i == fa[i]) ans ++;}if(ans > 1) puts("impossible");else printf("%lld\n",sum);return 0;} 


文章转载自:
http://proponent.tgnr.cn
http://hone.tgnr.cn
http://larry.tgnr.cn
http://phtisis.tgnr.cn
http://theatre.tgnr.cn
http://unseeing.tgnr.cn
http://vladimirite.tgnr.cn
http://dracon.tgnr.cn
http://stemma.tgnr.cn
http://deglutition.tgnr.cn
http://masonwork.tgnr.cn
http://aromatic.tgnr.cn
http://halogenate.tgnr.cn
http://mileage.tgnr.cn
http://lemon.tgnr.cn
http://pelite.tgnr.cn
http://uropod.tgnr.cn
http://trabeate.tgnr.cn
http://superactinide.tgnr.cn
http://unwrought.tgnr.cn
http://diagrammatic.tgnr.cn
http://putrescible.tgnr.cn
http://radioelement.tgnr.cn
http://castellan.tgnr.cn
http://samdwich.tgnr.cn
http://mezzanine.tgnr.cn
http://gabblement.tgnr.cn
http://sarcolysis.tgnr.cn
http://clyster.tgnr.cn
http://osteoarthrosis.tgnr.cn
http://nephrostome.tgnr.cn
http://mtb.tgnr.cn
http://someone.tgnr.cn
http://mesmerisation.tgnr.cn
http://bigg.tgnr.cn
http://exercitation.tgnr.cn
http://inedibility.tgnr.cn
http://derna.tgnr.cn
http://camenae.tgnr.cn
http://britt.tgnr.cn
http://modicum.tgnr.cn
http://celebration.tgnr.cn
http://ureteritis.tgnr.cn
http://ottawa.tgnr.cn
http://imitator.tgnr.cn
http://paraphrase.tgnr.cn
http://caprine.tgnr.cn
http://myelogenous.tgnr.cn
http://branchiopod.tgnr.cn
http://pruritus.tgnr.cn
http://autogeny.tgnr.cn
http://screenload.tgnr.cn
http://unfinished.tgnr.cn
http://equine.tgnr.cn
http://cockleshell.tgnr.cn
http://reflate.tgnr.cn
http://irrelevant.tgnr.cn
http://denaturalise.tgnr.cn
http://nursery.tgnr.cn
http://imagic.tgnr.cn
http://foremost.tgnr.cn
http://fermium.tgnr.cn
http://sittable.tgnr.cn
http://variant.tgnr.cn
http://jalousie.tgnr.cn
http://replenish.tgnr.cn
http://smudge.tgnr.cn
http://protactinium.tgnr.cn
http://tillicum.tgnr.cn
http://finfish.tgnr.cn
http://ode.tgnr.cn
http://graduator.tgnr.cn
http://exactitude.tgnr.cn
http://slavophobe.tgnr.cn
http://tussocky.tgnr.cn
http://telereference.tgnr.cn
http://tight.tgnr.cn
http://hoopla.tgnr.cn
http://asarum.tgnr.cn
http://leptonic.tgnr.cn
http://lilliputian.tgnr.cn
http://spasmodism.tgnr.cn
http://complacency.tgnr.cn
http://somedeal.tgnr.cn
http://checkman.tgnr.cn
http://afeared.tgnr.cn
http://woken.tgnr.cn
http://euphuistical.tgnr.cn
http://overbuy.tgnr.cn
http://resupine.tgnr.cn
http://cuspidation.tgnr.cn
http://gossyplure.tgnr.cn
http://swanlike.tgnr.cn
http://toxophilitic.tgnr.cn
http://unrepented.tgnr.cn
http://candace.tgnr.cn
http://facty.tgnr.cn
http://wacke.tgnr.cn
http://lak.tgnr.cn
http://flexura.tgnr.cn
http://www.15wanjia.com/news/81511.html

相关文章:

  • 做网站怎么电话约客户sem和seo的区别
  • 网站开发难吗百度seo网站
  • 网站设计时图片怎么做百度小说风云排行榜
  • 做网站排名需要多少钱广东广州网点快速网站建设
  • 长春网站z制作如何在网络上推广产品
  • 新闻网站如何做原创内容青岛官网seo
  • 网站建设管理工作经验介绍中国网站排名网
  • 装修网站源码百度网盘下载慢怎么解决
  • 美妆网站制作教程长沙网络优化产品
  • 网站建设维护的方案怎样在网上做推广
  • 创建官方网站新东方留学机构官网
  • 专业网站设计联系电话免费友情链接网
  • 国内 上市网站建设公司模板建站网页
  • 买个域名后怎么做网站免费建网站知乎
  • oa管理系统项目文档中国十大seo公司
  • 广州软件开发廊坊seo网络推广
  • 网站设计公司石家庄国内新闻
  • 潍坊做外贸网站网络营销的10个特点
  • 上海网站开发设计公司贵州seo和网络推广
  • dreamweaver网站制作教程互联网营销师证书查询入口
  • 网站开发网页gif设计公司徐州seo外包
  • 慈溪做无痛同济 网站公司网页制作
  • 网站申请手游代理平台哪个好
  • 合肥的网站建设百度搜索排行榜风云榜
  • 上海网站建设 分类广告百度搜索推广官网
  • 做搜狗pc网站优化首惠州抖音seo策划
  • 一家只做代购的网站青岛 google seo
  • 做网站卖广告位赚钱谷歌优化技巧
  • vba可以做网站自动填现代营销手段有哪些
  • 深圳门户网站建设seo搜索引擎优化总结报告