题目:在一个平面上有很多点,其中一些点已经被直线段连接,现在要把所有点连成一个整体,
要求新加入的直线段长度和最小。
分析:最小生成树。这里使用kruskal算法,先把一直线段的集合合并(并查集),然后在计算即可。
说明:╮(╯▽╰)╭。
#include
#include
#include
#include
#include
#include
usi...
分类:
其他好文 时间:
2015-04-03 19:25:03
阅读次数:
146
POJ 1751 Highways (Kruskal 最小生成树)...
分类:
其他好文 时间:
2015-03-18 01:17:20
阅读次数:
113
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that c...
分类:
其他好文 时间:
2015-03-11 18:42:08
阅读次数:
150
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we nee...
分类:
其他好文 时间:
2015-03-11 14:57:06
阅读次数:
154
A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a progra...
分类:
其他好文 时间:
2015-03-11 00:41:44
阅读次数:
142
DescriptionThe island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. T...
分类:
其他好文 时间:
2015-03-08 15:37:20
阅读次数:
135
HighwaysTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 23426Accepted: 10829DescriptionThe island nation of Flatopia is perfectly flat. Unfo....
分类:
其他好文 时间:
2015-03-06 22:12:54
阅读次数:
172
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different ga...
分类:
其他好文 时间:
2015-03-03 22:14:52
阅读次数:
212
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we nee...
分类:
其他好文 时间:
2015-02-25 21:11:19
阅读次数:
141
只要把prim算法稍微改一下就可以了。
#include
#include
#include
#include
using namespace std;
const int N=505;
const int inf=1<<28;
int cost[N][N],mincost[N];
bool used[N];
int n;
int prim()
{
int _max=0;...
分类:
其他好文 时间:
2015-02-15 16:36:39
阅读次数:
182