zoukankan      html  css  js  c++  java
  • POJ 2349 Arctic Network (最小生成树第K大(小)边)

    Arctic Network
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 13108   Accepted: 4256

    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

     
    题意:两个城镇连接有两种方式,卫星和无线技术,卫星连接不需要代价,无线技术距离越远代价越大,M个城镇有N个卫星,求无限技术使用最大距离
    分析:求最小生成树中最大的第K条边
    当N==0要特判
    只是很没搞懂为什么同样一份代码交G++就WA交C++就AC,求大牛解释ORZ
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<stdlib.h>
    #include<algorithm>
    #define LL __int64
    using namespace std;
    const int MAXN=1000+5;
    int kase,n,m;
    double ans[MAXN*MAXN/2];
    int p[MAXN];
    struct node
    {
        double x,y;
    }po[MAXN];
    struct edge
    {
        int u,v;
        double val;
        bool operator<(const edge A)const
        {
            return val<A.val;
        }
    }a[MAXN*MAXN/2];
    
    double calc(node A,node B)
    {
        return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) );
    }
    
    int findfa(int x)
    {
        return p[x]==x?x:p[x]=findfa(p[x]);
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        scanf("%d",&kase);
        while(kase--)
        {
            scanf("%d %d",&n,&m);
            for(int i=1;i<=m;i++)
                scanf("%lf %lf",&po[i].x,&po[i].y);
    
            int cnt=1;
            for(int i=1;i<=m;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    a[cnt].u=i;
                    a[cnt].v=j;
                    a[cnt++].val=calc(po[i],po[j]);
                }
            }
            sort(a+1,a+1+cnt);
            for(int i=1;i<=m;i++) p[i]=i;
    
            int res=0;
            for(int i=1;i<=cnt;i++)
            {
                int u=a[i].u;
                int v=a[i].v;
                int x=findfa(u);
                int y=findfa(v);
                if(x!=y)
                {
                    p[x]=y;
                    ans[res++]=a[i].val;
                    if(res==m-1) break;
                }
            }
            if(n==0) printf("%.2lf
    ",ans[res-1]);
            else printf("%.2lf
    ",ans[res-n]);
        }
        return 0;
    }
    View Code
     
     
  • 相关阅读:
    安装python3的详细教程
    MySQL中的各种引擎
    MySQL的语句执行顺序
    MySQL 5.7新增加的json数据类型
    MySQL5.6 PERFORMANCE_SCHEMA 说明
    MySQL中的sys系统数据库是干嘛的
    MySQL中information_schema数据库是干啥的
    mysql中You can’t specify target table for update in FROM clause错误解决方法
    win10 localhost 解析为::1 的解决办法
    python 中对象is和==是怎么比较的
  • 原文地址:https://www.cnblogs.com/clliff/p/4709389.html
Copyright © 2011-2022 走看看