摘要:hdu1233: http://acm.hdu.edu.cn/showproblem.php?pid=1233题意:全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。解法:最小生成树:Kruskalcode:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int v[10000],k[10000],w[10000],r[
阅读全文
摘要:hud1875: http://acm.hdu.edu.cn/showproblem.php?pid=1875题意:给出c个点的坐标,若点与点之间的距离大于1000或小于10则不能建桥,建桥费用为每米100元,求使得所有点能相通的最小费用,若不能相通,则输出“oh!"。解法:最小生成树prim。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usin
阅读全文
摘要:hdu1879: http://acm.hdu.edu.cn/showproblem.php?pid=1879题意:给出修建各条路的费用和是否已修(1为已修,0为未修),求要使所有点直接或者间接相连的最少费用解法:只需将已修的路的费用改为0,然后求最小生成树即可。法一:prim:code:#include<iostream>#include<cstdlib>#include<cstdlib>#include<algorithm>using namespace std;int v[110][110],sign[110];const int inf=
阅读全文