POj 2349 Arctic Network

来源:互联网 发布:淘宝网中年女装春装 编辑:程序博客网 时间:2024/05/22 22:34

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

1
2 4
0 100
0 300
0 600
150 750
Sample Output

212.13

在g++下只有%f能过,真是服气,就是一个简单的最下生成树,直接用kruskal或者prim跑一下,输出连接边的第s大的边就行

代码如下:

#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<string>using namespace std;const int MAX_V = 550;int pre[MAX_V];int x[MAX_V],y[MAX_V];int pos[MAX_V];int s,p;struct Edge{    int x,y,z;}q[MAX_V*MAX_V];int Find(int x){    int r = x;    while(pre[r] != r)        r = pre[r];    int i = x,j;    while(i != r){        j = pre[i];        pre[i] = r;        i = j;    }    return r;}bool add(int x,int y){    int fx = Find(x),fy = Find(y);    if(fx != fy){        pre[fx] = fy;        return true;    }    return false;}bool cmp(Edge a,Edge b){    return a.z < b.z;}int main(void){    int t;    scanf("%d",&t);    while(t--){        scanf("%d %d",&s,&p);        for(int i=1;i<=p;i++){            scanf("%d %d",&x[i],&y[i]);        }        int top = 0;        for(int i=1;i<=p;i++){            for(int j=i+1;j<=p;j++){                int dis = pow(x[i]-x[j],2)+pow(y[i]-y[j],2);                q[++top] = (Edge){i,j,dis};            }        }        for(int i=1;i<=p;i++)            pre[i] = i;        int Count = 0,tt = 0;        sort(q+1,q+1+top,cmp);        for(int i=1;i<=top;i++){            if(add(q[i].x,q[i].y)){                Count++;                pos[++tt] = i;            }            if(Count == p-1)    break;        }        tt -= (s-1);        printf("%.2f\n",sqrt(q[pos[tt]].z));//就是这里,真是服气    }    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脸被自己扣破了怎么办 6s安装不了软件怎么办 苹果6s特别卡怎么办 苹果手机4g网慢怎么办 大王卡玩王者卡怎么办 荣耀7c手机卡顿怎么办 华为6x手机卡顿怎么办 荣耀7c手机老卡怎么办 苹果6打王者卡怎么办 电脑玩游戏显示显卡不行怎么办 笔记本玩游戏显卡不行怎么办 笔记本玩英雄联盟有点卡怎么办 英语考试作文抄了阅读理解怎么办 qq账号被盗怎么办很久了 想玩线上德州没有渠道怎么办 手机玩久了头晕怎么办 玩3d游戏头晕恶心怎么办 win10打cf没声音怎么办 英雄联盟玩家尚未准备就绪怎么办 玩手机想吐应该怎么办 玩手机多了头晕怎么办 玩cf老是无响应怎么办 玩穿越火线好卡怎么办 绝地求生画质卡顿怎么办 手机热点玩lol卡怎么办 一加6直播触手黑屏怎么办 ipad应用商店密码忘记了怎么办 爱派忘记了密码怎么办 爱派id密码忘了怎么办 爱派密码忘了怎么办 爱派的密码忘了怎么办 苹果爱派密码忘了怎么办 鼠标无法识别的usb设备怎么办 电脑鼠标无法识别usb设备怎么办 win7电脑用户密码忘了怎么办 联想win7旗舰版开不了机怎么办 驱动都被卸载了怎么办 电脑密码忘了怎么办w7旗舰版 笔记本电脑密码忘了怎么办w7 windows一键还原了怎么办 戴尔笔记本电脑键盘没反应怎么办