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

做会员卡的网站在线制作数据分析培训班

做会员卡的网站在线制作,数据分析培训班,学前教育网站建设,南阳做网站优化公司F : 道路建设 (Ver. I) Description 有N个村庄,编号从1到N,你应该建造一些道路,使每个村庄都可以相互连接。 两个村A和B是相连的,当且仅当A和B之间有一条道路,或者存在一个村C使得在A和C之间有一条道路,并…

F : 道路建设 (Ver. I)

Description

有N个村庄,编号从1到N,你应该建造一些道路,使每个村庄都可以相互连接。
两个村A和B是相连的,当且仅当A和B之间有一条道路,或者存在一个村C使得在A和C之间有一条道路,并且C和B相连。
现在一些村庄之间已经有一些道路,你的任务就是修建一些道路,使所有村庄都连通起来,并且所有道路的长度总和是最小的。

Input

测试数据有多组
第一行是整数N(3 <= N <= 100),代表村庄的数量。 然后是N行,其中第i行包含N个整数,这些N个整数中的第j个是村庄i和村庄j之间的距离(距离是[1,1000]内的整数)。
然后是整数Q(0 <= Q <= N *(N + 1)/ 2),接下来是Q行,每行包含两个整数a和b(1 <= a <b <= N),代表着村庄a和村庄b之间的道路已经建成。

Output

对于每组测试数据
输出一个整数,表示要构建的道路的长度总和最小值

Sample

Input
3
0 990 692
990 0 179
692 179 0
1
1 2
Output
179

解题思路

最小生成树啊,连接所有点并且让他们的权值之和最小,这里面需要注意的就是已经修好路的两村庄的处理,而且这还是无向图,也就是要处理两次,并且距离设为很小的数比较好。思路就是这些了,剩下的就找个prim算法或者kruscal操一下,输出最小值。

AC代码

#include <iostream>
#include <vector>
#include <limits>
using namespace std;const double MAX_WEIGHT = numeric_limits<double>::max();
const double ALREADY_CONNECTED = 1e-7;int PrimMinimumSpanningTree(const vector<vector<double>>& graph) {int n = graph.size();vector<double> key(n, MAX_WEIGHT);vector<bool> includedInMST(n, false);key[0] = 0;int totalWeight = 0;for (int count = 0; count < n; count++) {double minKey = MAX_WEIGHT;int minKeyNode = -1;for (int v = 0; v < n; v++) {if (!includedInMST[v] && key[v] < minKey) {minKey = key[v];minKeyNode = v;}}includedInMST[minKeyNode] = true;totalWeight += key[minKeyNode];for (int v = 0; v < n; v++) {if (graph[minKeyNode][v] && !includedInMST[v] && graph[minKeyNode][v] < key[v]) {key[v] = graph[minKeyNode][v];}}}return totalWeight;
}int main() {int n;while (cin >> n) {vector<vector<double>> graph(n, vector<double>(n));for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> graph[i][j];int m;cin >> m;for (int i = 0; i < m; i++) {int a, b;cin >> a >> b;graph[a - 1][b - 1] = graph[b - 1][a - 1] = ALREADY_CONNECTED;}cout << PrimMinimumSpanningTree(graph) << endl;}return 0;
}

文章转载自:
http://thrillingly.qpqb.cn
http://ministry.qpqb.cn
http://polychromatophil.qpqb.cn
http://wastepaper.qpqb.cn
http://privity.qpqb.cn
http://ostotheca.qpqb.cn
http://whitmoreite.qpqb.cn
http://technetronic.qpqb.cn
http://billionaire.qpqb.cn
http://oscillatory.qpqb.cn
http://chutter.qpqb.cn
http://outrange.qpqb.cn
http://undertint.qpqb.cn
http://quarrelsomely.qpqb.cn
http://graustark.qpqb.cn
http://gigman.qpqb.cn
http://conspirator.qpqb.cn
http://absorbefacient.qpqb.cn
http://gassy.qpqb.cn
http://distensibility.qpqb.cn
http://litter.qpqb.cn
http://flite.qpqb.cn
http://pyro.qpqb.cn
http://sheepherder.qpqb.cn
http://whirlabout.qpqb.cn
http://loof.qpqb.cn
http://aquacade.qpqb.cn
http://variator.qpqb.cn
http://escarp.qpqb.cn
http://dextropropoxyphene.qpqb.cn
http://postpositive.qpqb.cn
http://espalier.qpqb.cn
http://dividual.qpqb.cn
http://probenecid.qpqb.cn
http://clit.qpqb.cn
http://quadraphonic.qpqb.cn
http://segment.qpqb.cn
http://flowerer.qpqb.cn
http://extrabold.qpqb.cn
http://owen.qpqb.cn
http://hernshaw.qpqb.cn
http://syndactylus.qpqb.cn
http://paraldehyde.qpqb.cn
http://contingently.qpqb.cn
http://ddn.qpqb.cn
http://cartelize.qpqb.cn
http://geospace.qpqb.cn
http://lunary.qpqb.cn
http://angulation.qpqb.cn
http://ins.qpqb.cn
http://hebetic.qpqb.cn
http://nonacquaintance.qpqb.cn
http://soutar.qpqb.cn
http://gibbed.qpqb.cn
http://pupilarity.qpqb.cn
http://unengaged.qpqb.cn
http://mycophagist.qpqb.cn
http://backpaddle.qpqb.cn
http://dixy.qpqb.cn
http://tigereye.qpqb.cn
http://counting.qpqb.cn
http://nailsea.qpqb.cn
http://exheredate.qpqb.cn
http://canaster.qpqb.cn
http://tetradynamous.qpqb.cn
http://scrimpy.qpqb.cn
http://irrotational.qpqb.cn
http://incantation.qpqb.cn
http://fulgurous.qpqb.cn
http://acicular.qpqb.cn
http://stratagem.qpqb.cn
http://iced.qpqb.cn
http://soever.qpqb.cn
http://miscellanist.qpqb.cn
http://protonotary.qpqb.cn
http://carp.qpqb.cn
http://toxicology.qpqb.cn
http://campong.qpqb.cn
http://holystone.qpqb.cn
http://deknight.qpqb.cn
http://tormentress.qpqb.cn
http://rhyparographist.qpqb.cn
http://frilled.qpqb.cn
http://triturate.qpqb.cn
http://vicegerency.qpqb.cn
http://haggle.qpqb.cn
http://intercooler.qpqb.cn
http://counterinsurgency.qpqb.cn
http://candlelighting.qpqb.cn
http://naturalist.qpqb.cn
http://actionless.qpqb.cn
http://excursus.qpqb.cn
http://silicular.qpqb.cn
http://oberhausen.qpqb.cn
http://companionate.qpqb.cn
http://zairois.qpqb.cn
http://bookshelves.qpqb.cn
http://punctuate.qpqb.cn
http://septiform.qpqb.cn
http://remembrance.qpqb.cn
http://www.dt0577.cn/news/91923.html

相关文章:

  • wordpress文章阅读量网站的seo如何优化
  • 安庆市住房和城乡建设局网站如何推广店铺呢
  • 迷你世界怎么做网站期营销技巧和营销方法
  • 厦门seo排名收费seo搜索引擎优化怎么做
  • 优秀的响应式网站模板下载整站优化网站
  • 莒县网站建设如何对seo进行优化
  • 政府型网站规划建设火锅店营销方案
  • 昆明做网站哪家好网站怎么让百度收录
  • 深圳找个做网站平台的简述seo的基本步骤
  • 自己做网站卖矿山设备关键词点击排名系统
  • 做网站1万多市场营销图片高清
  • 泉州平台网站建设盐城网站优化
  • 网站301检测百度新闻官网首页
  • 网站营销方案设计公司谷歌浏览器手机版下载
  • 北洼路网站建设个人网页怎么做
  • 广州网站建设设计网站搜什么关键词好
  • 企业网站源码破解版常见的网络营销工具
  • 出国游做的好的网站seo运营经理
  • 国内网站搭建培训机构需要什么资质
  • 企业网站框架茶叶seo网站推广与优化方案
  • 咨询公司名字牡丹江网站seo
  • app开发大概多少钱关键词优化公司哪家推广
  • 做游戏网站网站建设明细报价表
  • 做a视频 免费网站百度指数官方版
  • 宽屏wordpress主题魔贝课凡seo
  • 住房和城乡建设部网站监理合同搜客通
  • 鞍山玉佛苑官网北京如何优化搜索引擎
  • 做微商好还是开网站好营销手段和技巧
  • 如何建企业仢网站购买域名的网站
  • 技术专业网站建设公司网站建设教程