在北极圈有一些基地,这些基地需要建立通讯网络,他们可以通过卫星直接通信或者无线通信,基地有S个卫星,N个基地,不过无线通信的传输距离是D,距离越远费用越高,现在想知道D最小是多少。

分析:使用krusal添加p-s条边就行了,因为剩下的边肯定会比已经添加的边要长,在添加的边里面选取最长的那条,也就是最后添加的那条。
************************************************************************************
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
using namespace std; #define maxn 505 int f[maxn];
struct node
{
    int u, v;
    double len;
    friend bool operator < (node a, node b)
    {
        return a.len > b.len;
    }
};
struct point{double x, y;}p[maxn];
double Len(point a, point b)
{
    double x = a.x - b.x;
    double y = a.y - b.y;
    double l = sqrt(x*x+y*y);     return l;
}
int Find(int x)
{
    if(f[x] != x)
        f[x] = Find(f[x]);
    return f[x];
} int main()
{
    int T;     scanf("%d", &T);     while(T--)
    {
        int S, N, u, v;
        node s;
        priority_queue<node> Q;         scanf("%d%d", &S, &N);         for(s.u=1; s.u<=N; s.u++)
        {
            f[s.u] = s.u;
            scanf("%lf%lf", &p[s.u].x, &p[s.u].y);
            for(s.v=1; s.v<s.u; s.v++)
            {
                s.len = Len(p[s.u], p[s.v]);
                Q.push(s);
            }
        }         while(Q.size() && S < N)
        {
            s = Q.top();Q.pop();
            u = Find(s.u), v = Find(s.v);             if(u != v)
            {
                S++;
                f[u] = v;
            }
        }         printf("%.2f\n", s.len);
    }     return 0;
}

G - Arctic Network - poj2349的更多相关文章

  1. G - Arctic Network

    G - Arctic Network   #include<cmath> #include<cstdio> #include<cstring> #include&l ...

  2. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

  3. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  4. POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19113   Accepted: 6023 D ...

  5. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  6. POJ2349 Arctic Network(Prim)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16968   Accepted: 5412 D ...

  7. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9557   Accepted: 3187 De ...

  8. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  9. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. Python开发【第九篇】:HTML (二)

    python[第十四篇]HTML基础 时间:2016-08-08 20:57:27      阅读:49      评论:0      收藏:0      [点我收藏+] 标签: 什么是HTML? H ...

  2. noi 7221 拯救公主 (状态压缩+bfs)

    /* 这题实在调糊了 借鉴的题解的一些判断方法 位运算大法好 - - 因为要集齐所有的宝石所以状态压缩一下 f[i][j][s]将s化为二进制 每一0表示该宝石没有 1表示该宝石有 有:到(i,j)这 ...

  3. Linq101-Aggregate

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Aggrega ...

  4. oracle事务特性详解

    原子性 事务是一个完整的操作.事务的各步操作是不可分的(原子的):要么都执行,要么都不执行. -- 创建表 create table account_money ( id number(4) not ...

  5. IOS开发常用的linux命令

    pwd 在Linux层次结构中,用户可以在被授权的任意目录下利用mkdir命令创建新目录,也可以利用cd命令从一个目录转换到另一个目录.然而,没有提示符来告知用户目前处于哪一个目录中.想要知道当前所处 ...

  6. C++ Primer 5th 第15章 面向对象程序设计

    面向对象程序设计的核心思想是:数据抽象.继承和动态绑定. 数据抽象:将类的接口与实现分离: 继承:定义相似类型并对相似关系建模: 动态绑定:一定程度上上忽略相似类型间的区别,用同一方式使用它们. 1. ...

  7. JavaScript-学习一字符串

    字符串可以存储一系列字符,如 "John Doe". 字符串可以是插入到引号中的任何字符.你可以使用单引号或双引号: 用于字符串的 + 运算符 + 运算符用于把文本值或字符串变量加 ...

  8. [HTML5 Canvas学习]绘制矩形

    1.使用strokeRect和fillRect方法绘制矩形 a.strokeRect是绘制一个不填充的矩形 b.fillRect是绘制一个填充的矩形 代码: <script> var ca ...

  9. Chrome不支持本地Ajax请求解决?

    今天用JQuery操作Ajax时,使用load方法加载html块 结果提示: XMLHttpRequest cannot load file~~~~~~~Origin 'null' is theref ...

  10. js JSONP实例

    <script type="text/javascript"> $(function(){ checkuserstatus(); $('#loginbutton').c ...