zoukankan      html  css  js  c++  java
  • Arctic Network POJ

    题目链接:https://vjudge.net/problem/POJ-2349

    思路:

    题目说,有很多个网络点,每个网络点需要雷达相连,题目还会给指定数量的超级雷达,

    每两个超级雷达直接可以直接连接,且没有距离限制,问能使得所有网络点相连,

    雷达信号最小半径需要多大。我们可以直接跑一次最小生成树,然后把每个点的权值从大到小排序,

    因为有超级雷达的存在,那么我们可以让最大权值的地方用超级雷达让这个权值变为0。

     1 include <stdio.h>
     2 #include <iostream>
     3 #include <queue>
     4 #include <math.h>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 const int N = (int)1e3 + 10;
     9 const int inf = (int)1e9;
    10 double px[N];
    11 double py[N];
    12 double g[N][N];
    13 double dis[N];
    14 bool vis[N];
    15 int s,p;
    16 
    17 struct node{
    18     int loc;
    19     double w;
    20     bool friend operator<(const node & a,const node& b){
    21         return a.w > b.w;
    22     }
    23 };
    24 priority_queue<node > que;
    25 
    26 bool cmp(double x,double y){
    27     return x > y;
    28 }
    29 
    30 inline double dist(int a,int b){
    31     return sqrt((px[a]-px[b])*(px[a]-px[b])+(py[a]-py[b])*(py[a]-py[b]));
    32 }
    33 
    34 void build_map(){
    35 
    36     for(int i = 1; i <= p; i++)
    37         for(int j = 1; j <= p; j++)
    38             g[i][j] = g[j][i] = dist(i,j);
    39 
    40 }
    41 
    42 double prime(){
    43 
    44     for(int i = 1; i <= p; i++){
    45         vis[i] = 0;
    46         dis[i] = inf;
    47     }
    48 
    49     while(!que.empty()) que.pop();
    50 
    51     que.push(node{1,0});
    52     dis[1] = 0;
    53 
    54     while(!que.empty()){
    55         int u = que.top().loc;
    56         que.pop();
    57         vis[u] = true;
    58 
    59         for(int v = 1; v <= p ;v++){
    60             if(!vis[v] && dis[v] > g[u][v]){
    61                 dis[v] = g[u][v];
    62                 que.push(node{v,dis[v]});
    63             }
    64         }
    65     }
    66     sort(dis+1,dis+1+p,cmp);
    67     /*
    68     for(int i = 1; i <= p; i++)
    69         printf("%lf
    ",dis[i]);
    70     */
    71 
    72 
    73     return dis[s];
    74 }
    75 
    76 int main(){
    77 
    78     int T;
    79     scanf("%d",&T);
    80 
    81     while(T--){
    82         scanf("%d%d",&s,&p);
    83 
    84         for(int i = 1; i <= p; i++)
    85             scanf("%lf%lf",&px[i],&py[i]);
    86 
    87         build_map();
    88 
    89         printf("%.2f
    ",prime());
    90     }
    91 
    92     return 0;
    93 }
  • 相关阅读:
    我开博客了,啦啦啦.
    cf593div2
    Comet OJ
    cf591div2abc
    cfround586ac
    cf589div2
    cf573div2
    Codeforces Round #569 (Div. 2)
    uva11729 水题
    luogu1984 [SDOI2008] 烧水问题
  • 原文地址:https://www.cnblogs.com/SSummerZzz/p/11822989.html
Copyright © 2011-2022 走看看