zoukankan      html  css  js  c++  java
  • uva10369 Arctic Network( 最小生成树)

    这道题数据s不是100。。我开了1000。。坑。。不停RE

    做法就是求出一个最小生成树然后求 第n-s边的大小

    题目:

    Problem C: Arctic Network

    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.

    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). 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
    

    代码:

     1 #include <iostream>
     2 #include <cmath>
     3 #include <algorithm>
     4 #include <cstdio>
     5 #include <memory.h>
     6 using namespace std;
     7 
     8 struct V
     9 {
    10   double x,y;
    11 }P[2000];
    12 
    13 struct Edge
    14 {
    15     int f,t;
    16     double w;
    17 
    18     bool const operator <(const Edge & x) const
    19     {
    20 
    21         return w<x.w;
    22     }
    23 }E[400000];
    24 
    25 double dist(int x,int y){
    26     return sqrt(  (P[x].x-P[y].x)*(P[x].x-P[y].x)+(P[x].y-P[y].y)*(P[x].y-P[y].y)  );
    27 }
    28 
    29 int F[2000];
    30 
    31 double ans[2000];
    32 int find(int x){return F[x]==x?x:F[x]=find(F[x]);}
    33 int satt;
    34 int vv;
    35 int main()
    36 {
    37  //   cout<<dist()
    38     int tst;
    39     cin>>tst;
    40     while(tst--)
    41     {
    42         cin>>satt>>vv;
    43 
    44         for(int i=0;i<=vv;i++)F[i]=i;
    45 
    46         for(int i=0;i<vv;i++)
    47         {
    48             cin>>P[i].x>>P[i].y;
    49         }
    50 
    51         int pe=0;
    52 
    53         for(int i=0;i<vv;i++)
    54         {
    55             for(int j=0;j<vv;j++)
    56             {
    57                 if(i!=j)
    58                 {
    59                     E[pe].f=i;
    60                     E[pe].t = j;
    61                     E[pe].w = dist(i,j);
    62                     pe++;
    63                 }
    64             }
    65         }
    66         sort(E,E+pe);
    67 
    68 
    69 
    70         int pans=0;
    71         for(int i=0;i<pe;i++)
    72         {
    73             int x = find(E[i].f), y = find(E[i].t);
    74             if(x!=y)
    75             {
    76                 pans++;
    77                 if(pans== vv-satt)
    78                 {
    79                     printf("%.2lf
    ",E[i].w);
    80                 }
    81 
    82                 F[x] =y;
    83             }
    84         }
    85 //        memset(ans,0,sizeof(ans));
    86     }
    87 
    88     return 0;
    89 }
  • 相关阅读:
    mybatis-plus 相关
    Nginx 相关
    Docker 相关
    shiro & jwt
    Java GC
    C++ Q&A
    epoll ET & LT
    关于 free 命令显示内存使用情况问题
    Metaprogramming in Ruby: It’s All About the Self
    On The Value Of Fundamentals In Software Development (基础知识在软件开发中的价值)
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3508819.html
Copyright © 2011-2022 走看看