摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1162题目大意我就不说了,很容易看明白。直接上代码吧,还是,只要你会Kruskal,这个题目没有什么难度。View Code #include<iostream>#include<algorithm>#include<cmath>#include<string>#include<cstring>using namespace std;int father[10005], Enums, Count;double MinL;struct Point
阅读全文
摘要:题目:http://poj.org/problem?id=1861说下题意,给出节点个数m和边数n,下面n行给出边(x,y)以及权值w。输出第一行为最小生成树中的最大边权值,第二行为一个可行生成树方案的边数k,下面k行为可行生成树的k条边。题目是Special Judge,意思就是不具有唯一解,可能有多解,样例输出为以下结果也可算对。131 32 42 3一样按照Kruskal解题即可,结果虽然不唯一,但是最小生成树一定是可行解之一。将边加入生成树时记录最大权值和边信息然后输出即可。View Code #include "iostream"#include "al
阅读全文
摘要:DescriptionFarmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. T
阅读全文
摘要:DescriptionThere are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B, or there exists a village C such that there is a road bet
阅读全文
摘要:DescriptionYou are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough funds to start your business properly and are relying on parts you have found in an old warehouse you bought. Among your finds is a single spool of cable and a lot of
阅读全文
摘要:DescriptionThe Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose t
阅读全文
摘要:克鲁斯卡尔算法(Kruskal's algorithm)是两个经典的最小生成树算法的较为简单理解的一个。 这里面充分体现了贪心算法的精髓。 大致的流程可以用一个图来表示。这里的图的选择借用了Wikipedia上的那个。非常清晰且直观。 首先第一步,我们有一张图,有若干点和边 如下图所示: . . . . . . 第一步我们要做的事情就是将所有的边的长度排序,用排序的结果作为我们选择边的依据。 这里再次体现了贪心算法的思想。资源排序,对局部最优的资源进行选择。 排序完成后,我们率先选择了边AD。 这样我们的图就变成了 . . . . . . 第二步,在...
阅读全文