Arctic Network(P2349)

来源:互联网 发布:海澜之家男装淘宝网 编辑:程序博客网 时间:2024/05/26 20:22

这个题是自己大概猜测着题意做的,


给出有几个频道,两个频道间可以用卫星传,不计算距离,这样就用PIM计算出加入的边排好序后根据S选倒数第几大的就行了,


#include<iostream>#include<stdlib.h>#include<math.h>#include<stdio.h>#include<algorithm>#include<queue>#include<string.h>#include<stack>#include<math.h>#include<stdlib.h>#include<list>#include<vector>using namespace std;double map[500][5000];int n,s;struct my{    double x;    double y;}point[500];int main(){    int i,j,k;    int t;    cin>>t;    while (t--)    {        cin>>s>>n;        for (i=0;i<n;i++)        {            cin>>point[i].x>>point[i].y;        }        for (i=0;i<n;i++)        {            for (j=i+1;j<n;j++)            {                map[i][j]=sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y));                map[j][i]=map[i][j];            }        }        bool vist[500];        memset(vist,false,sizeof(vist));        double ans[500];        double hi[500];        for (i=0;i<n;i++)        {            hi[i]=map[0][i];        }        k=n-1;        vist[0]=true;        int l=0;        while (k--)        {            double big=100000000.0;            for (i=0;i<n;i++)            {                if (!vist[i]&&big>hi[i])                    big=hi[i],j=i;            }            vist[j]=true;            ans[l++]=big;            //cout<<big<<endl;            for (i=0;i<n;i++)            {                if (!vist[i]&&hi[i]>map[i][j])                    hi[i]=map[i][j];            }        }        sort(ans,ans+l);        printf("%.2f\n",ans[n-s-1]);    }}




Arctic Network
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5310 Accepted: 1880

Description

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

12 40 1000 3000 600150 750

Sample Output

212.13

Source


原创粉丝点击