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
     
     
  • 相关阅读:
    AMD 开源照片级渲染引擎 Radeon ProRender
    删除集群mds
    删除集群mds
    一次旅途她和豆浆结缘,如今拥有70多家加盟店
    小伙居然开网店卖花,整整一年时间他做出了400万元的业绩
    带着800元现金开始创业,居然开出了十几家连锁超市
    北大学霸从小米离职,靠眼镜打开亿万市场
    广西农民靠养猪发家致富,采用新模式既有效益又保护生态
    在母婴产品领域他独领风骚,利润已经突破了1亿
    80后小伙白手起家做照明生意,为他创造了六千万元的业绩
  • 原文地址:https://www.cnblogs.com/clliff/p/4709389.html
Copyright © 2011-2022 走看看