zoukankan      html  css  js  c++  java
  • Arctic Network

    Arctic Network

    http://poj.org/problem?id=2349

    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 27794   Accepted: 8438

    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
    

    Source

     
    跑一遍最小生成树,然后把距离排个序就行
     
     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<cmath>
     6 using namespace std;
     7 
     8 struct sair{
     9     int x,y;
    10 }P[1005];
    11 
    12 struct DIS{
    13     int s,e;
    14     double dis;
    15 }dis[250005];
    16 
    17 double dist(sair x,sair y){
    18     return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
    19 }
    20 
    21 bool cmp(DIS a,DIS b){
    22     return a.dis<b.dis;
    23 }
    24 
    25 bool cmpp(double a,double b){
    26     return a>b;
    27 }
    28 
    29 int fa[100005];
    30 
    31 int Find(int x){
    32     int r=x,y;
    33     while(x!=fa[x]){
    34         x=fa[x];
    35     }
    36     while(r!=x){
    37         y=fa[r];
    38         fa[r]=x;
    39         r=y;
    40     }
    41     return x;
    42 }
    43 
    44 bool join(int x,int y){
    45     int xx=Find(x);
    46     int yy=Find(y);
    47     if(xx!=yy){
    48         fa[xx]=yy;
    49         return true;
    50     }
    51     return false;
    52 }
    53 
    54 double Dis[250005];
    55 
    56 int main(){
    57     int T;
    58     scanf("%d",&T);
    59     while(T--){
    60         int s,p;
    61         scanf("%d %d",&s,&p);
    62         for(int i=0;i<=p;i++){
    63             fa[i]=i;
    64         }
    65         for(int i=1;i<=p;i++){
    66             scanf("%d %d",&P[i].x,&P[i].y);
    67         }
    68         int co=0;
    69         for(int i=1;i<=p;i++){
    70             for(int j=i+1;j<=p;j++){
    71                 dis[++co].s=i;
    72                 dis[co].e=j;
    73                 dis[co].dis=dist(P[i],P[j]);
    74             }
    75         }
    76         sort(dis+1,dis+co+1,cmp);
    77         int Co=0;
    78         for(int i=1;i<=co;i++){
    79             if(join(dis[i].s,dis[i].e)){
    80                 Dis[Co++]=dis[i].dis;
    81             }
    82         }
    83 
    84         sort(Dis,Dis+Co,cmpp);
    85         printf("%.2f
    ",Dis[s-1]);
    86     }
    87 }
    View Code
     
  • 相关阅读:
    P12 向量组03--极大线性无关组
    超导体
    Matlab中disp、fprintf和sprintf有什么区别?
    点击word页面自动弹出信息检索很烦人
    Postman 官方中文版 v7.25.3
    无法为更新定位行。一些值可能已在最后一次读取后已更改解决办法
    Everything文件查找工具
    Delphi的DataSource事件
    Delphi中inherited问题
    delphi窗体继承
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/9965512.html
Copyright © 2011-2022 走看看