POJ2032 Arctic Network (Prim)

Source: Internet
Author: User

Arctic Network
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 16968 Accepted: 5412

Description

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Different communication technologies is to being used in establishing the Network:every outpost would have a radio trans Ceiver and some outposts would in addition has a satellite channel.
Any-outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, 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 is identical; That's, 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 is 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 all test case contains 1 <= s <=, the number of satellite channels, and S < P <=, t He number of outposts. P lines follow, giving the (x, y) coordinates of each outpost in km (coordinates is 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 is specified to 2 decimal points.

Sample Input

12 40 1000 3000 600150 750

Sample Output

212.13

Source

Waterloo local 2002.09.28 "test instructions" has s satellite and p posts, and there are two posts in the satellite that can communicate with each other; otherwise, a post can only communicate with posts that are less than or equal to D. Given the number of satellites and the coordinates of P posts, the minimum value of D is obtained. "Analysis" in order to practice prim. You can use prim to build the edge, save it, and then choose the edge from small to large order, the number of n-p-1 is the answer.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<functional>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intn=2005;Const intm=15005;DoubleEdg[n][n];DoubleLowcost[n];//record the minimum distance from the elements of I that are not joined to the tree collectionintn,m,t,v;DoubleD[n];BOOLcmpDoubleADoubleb) {returna<b;}structman{Doublex, y;intnum;} A[n];DoubleFun (Mans A,man b) {DoubleCnt=sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); returnCNT;}voidBuild () { for(intI=0; i<n;i++)    {         for(intj=i+1; j<n;j++) {Edg[i][j]=edg[j][i]=Fun (A[i],a[j]); }    }}voidPrim () {Doublesum=0; lowcost[0]=-1;  for(intI=1; i<n;i++) {Lowcost[i]=edg[0][i]; }     for(intI=1; i<n;i++){        DoubleMinn=inf;intK;  for(intj=0; j<n;j++){            if(lowcost[j]!=-1&&lowcost[j]<Minn) {k=j;minn=Lowcost[j]; }} sum+=Minn; D[v++]=Minn; LOWCOST[K]=-1;  for(intj=0; j<n;j++) {Lowcost[j]=min (lowcost[j],edg[k][j]); }} sort (D,d+v,cmp); printf ("%.2lf\n", d[n-m-1]);}intMain () {scanf ("%d",&t);  while(t--) {memset (EDG,0,sizeof(EDG)); memset (Lowcost,0,sizeof(lowcost)); memset (d,0,sizeof(d)); V=0; scanf ("%d%d",&m,&N);  for(intI=0; i<n;i++) {scanf ("%LF%LF",&a[i].x,&a[i].y); A[i].num=i;        } Build ();    Prim (); }    return 0;}
View Code

POJ2032 Arctic Network (Prim)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.