zoukankan      html  css  js  c++  java
  • Poj(2349),最小生成树的变形

    题目链接:http://poj.org/problem?id=2349

    Arctic Network
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 17032   Accepted: 5441

    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案例数,2个点是可以用无线的(用无线的点,到任何点的距离不受限制),4个点,下面是坐标,求最小生成树中的最大权值,和之前的不同点是在权值为0的点是不确定的。
    思路:照样求最小生成树,有2个点的距离为0,即可以在最小生成树中删掉两条最长的边。最靠后的那条边就是最大的权值。
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>
    
    using namespace std;
    
    int x[550];
    int y[550];
    
    struct Edge {
        int u,v;
        double w;
    }edge[550*550];
    
    int father[550];
    
    int Find_Set(int x)
    {
        if(x!=father[x])
            father[x] = Find_Set(father[x]);
        return father[x];
    }
    
    int cmp (Edge a,Edge b)
    {
        return a.w < b.w;
    }
    
    double ans[550];
    
    int main()
    {
        //freopen("input.txt","r",stdin);
        int cases;
        scanf("%d",&cases);
        while(cases--)
        {
            memset(ans,0,sizeof(ans));
            int s,n;
            scanf("%d%d",&s,&n);
            for(int i=0;i<n;i++)
               scanf("%d%d",&x[i],&y[i]);
    
            int cnt = 0;
            for(int i=0;i<n;i++)
                for(int j=0;j<i;j++)
                {
                    edge[cnt].u = i;
                    edge[cnt].v = j;
                    edge[cnt++].w = sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]));
                }
    
    
            for(int i=0;i<=n;i++)
                father[i] = i;
    
            sort(edge,edge+cnt,cmp);
    
            int k=0;
            for(int i=0;i<cnt;i++)
            {
                int fx = Find_Set(edge[i].u);
                int fy = Find_Set(edge[i].v);
                if(fx!=fy)
                {
                    father[fy] = fx;
                    ans[k]=edge[i].w;
                    k++;
                    if(k==n-1)
                        break;
                }
            }
            printf("%.2lf
    ",ans[n-s-1]);
        }
        return 0;
    }
  • 相关阅读:
    c coroutine
    leveldb(ssdb)性能、使用场景评估
    [微信协议分析] 多媒体
    [微信协议分析] 多点登陆
    [微信协议分析] 文本消息
    paxos(chubby) vs zab(Zookeeper)
    分布式一致性算法
    erlang 健壮性
    tcp 出现rst情况整理
    tcp_tw_reuse、tcp_tw_recycle 使用场景及注意事项
  • 原文地址:https://www.cnblogs.com/TreeDream/p/5748110.html
Copyright © 2011-2022 走看看