Poj2349:arctic Network (minimum spanning tree)

Source: Internet
Author: User

Total time limit:
2000ms
Memory Limit:
65536kB
Describe
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
Is test instructions a bit difficult to understand, the problem is still very simple.

Test instructions: There are n points given coordinates, between points and points can be radio or satellite communications, each point has a radio transceiver for radio communication, but only m points have satellite communication function. The distance of satellite communications can be infinitely large, but the distance of radio communication cannot exceed D, and the portion exceeding D will increase the cost of communication. To minimize the cost of communication.

In fact, is to seek a minimum spanning tree, m points have satellite communications, then there will be m-1 edge of the communication distance is infinite, in fact, this is the m-1 side without the cost calculation. The rest of the edges, find the maximum edge as the D value, so that all the remaining edges will not be greater than D, then no increase in communication costs. Save all the edge weights in the process of building the MST, then sort them in ascending order, removing the last m-1 (i.e. the largest m-1 edges, which use satellite communications), and the largest one is D; with AC code:

#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm>using namespace Std;struct node{int start;int end;double cost;} T[1001000];int CMP (node A,node b) {return a.cost <b.cost;} int per[1100];int Find (int x) {int r=x;while (R!=per[r]) R=per[r];return R; int join (int x,int y) {int fx=find (x), int fy=find (y), if (fx!=fy) {Per[fx]=fy;return 1;} return 0;} int main () {int k,m,n,p,i,j;int x[110010],y[110010];scanf ("%d", &p), while (p--) {for (i=0;i<1100;i++) per[i]=i; scanf ("%d%d", &m,&n), for (i=1;i<=n;i++) scanf ("%d%d", &x[i],&y[i]), K=0;for (i=1;i<=n;i++) for ( j=i+1;j<=n;j++) {t[k].start=i;t[k].end =j;t[k].cost =sqrt (1.0* (X[i]-x[j]) * (X[i]-x[j]) +1.0* (Y[i]-y[j]) * (y[i]-y[ j])); k++;} Sort (t,t+k,cmp); int v=0;double ans;for (i=0;i<k;i++) {if (Join (t[i].start,t[i].end)) v++;if (v==n-m) {Ans=t[i].cost ; break;}} printf ("%.2f\n", ans);}  return 0;}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Poj2349:arctic Network (minimum spanning tree)

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.