POJ2349 Arctic Network(手动翻译)(求最小生成树权值第几大的边 Prim写法)

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel. 
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts. 

Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Input
The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13


题意:自己写的时候有点想偷懒直接去看别人的翻译,果然还是自己读题理解得比较到位呀Orz

题目描述的就是给你m和n,接下来有n个顶点,在这n个顶点的图中构造最小生成树,找出这个最小生成树中权值第n-m大的那条边的权值。(就是m个卫星收发器可以抵偿两点之间的通讯代价d,也就是使dis[]为0,所以我们让m个卫星收发器替代权值最大的m条边)

----------------------------------------------------

算了还是手动翻译一遍吧

国防部希望在北极的几个哨所建立通讯网络,这里有两个通讯工具可供使用,一个是卫星收发器,一个是无线电收发器。卫星收发器可以没有代价的使两个哨所之间建立联系但只有m个,无线电收发器有无限个但是联系两个哨所之间需要代价d。给出每个哨所的坐标(x,y)(x,y都是整数,但两点之间的距离就不一定了),求出这个代价d最大是多少。

解题思路:

最大代价就是最小生成树中权值最大的边的权值呗,有了m个卫星收发器可以代替头m个权值最大的边,那么我们要找的就是第n-m大的权值的边的权值(好绕Orz

在初始的时候就应该注意下标,后面还要涉及到sort和输出,这里下标是从1开始的。

直接prim构造最小生成树,最后对树的权值的集合(都在dis数组里)排下序,直接输出要找的那条边的权值。


AC代码:

#include
#include
#include
#include
using namespace std;

#define INF 0x3f3f3f3f

struct node
{
	double x,y;
} q[610];

double mp[610][610],dis[610];
int book[610],n,m;

void prim()
{
	for(int i=1;i<=n;i++)
	{
		dis[i]=mp[1][i];
	}
	dis[1]=0;
	book[1]=1;
	for(int i=1;i<=n-1;i++)
	{
		int minn=INF,u;
		for(int j=1;j<=n;j++)
		{
			if(dis[j]

你可能感兴趣的:(ACM,图论一顿套模板,POJ2349,Prim)