在北极圈有一些基地,这些基地需要建立通讯网络,他们可以通过卫星直接通信或者无线通信,基地有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. Mock和injectMocks的区别

    @Mock private ForeCatalogManageServiceImpl foreCatalogManageServiceImpl; 如果是上面的写法,那么 红框方法里面的代码不会执行,这 ...

  2. 工时统计的sql练习--包含时间处理

    //按月统计,除去周末的考勤,(工时,请假,缺勤) --建表sql 创建[dbo].[AbsenceHourld]CREATE TABLE [dbo].[AbsenceHourld]( [id] [i ...

  3. Ext.grid.Panel表格分页

    转载:http://www.cnblogs.com/libingql/archive/2012/04/22/2464994.html cshtml @{ Layout = null; } <!D ...

  4. 黑马程序员-hashtable

    散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个映射函数叫做散列 ...

  5. win7+SQL2008无法打开物理文件 操作系统错误 5:拒绝访问 SQL Sever

    今天在win7+SQL2008的环境下操作分离附加数据库,分离出去然后再附加,没有问题.但是一把.mdf文件拷到其它文件夹下就出错,错误如下:无法打开物理文件 "E:\db\MyDB.mdf ...

  6. iOSUI基础——懒加载

    1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其get方法. 注意:如果是懒加载的话则一定要注意先判断是否已经有了,如果没有那么再去进行实例化 ...

  7. Swift - 14 - 字符串的基础操作

    //: Playground - noun: a place where people can play import UIKit // 拼接 var str = "Hello, playg ...

  8. java_log_02

    配置 在第一部分,我们将介绍配置 logback 的各种方法,给出了很多配置脚本例子.在第二部分,我们将介绍 Joran,它是一个通用配置框架,你可以在自己的项目里使用 Joran 一.Logback ...

  9. 【USACO 2.3.3】零数列

    [题目描述] 请考虑一个由1到N(N=3, 4, 5 ... 9)的数字组成的递增数列:1 2 3 ... N. 现在请在数列中插入“+”表示加,或者“-”表示减,“ ”表示空白(例如1-2 3就等于 ...

  10. 初涉JavaScript模式 (7) : 原型模式 【三】

    组合使用构造函数模式和原型模式 上篇,我们提到了原型模式的缺点,就是每个实例不能拥有自己的属性,因为纯原型模式所有的属性都是公开给每个实例的,故我们可以组合使用构造函数模式和原型模式.构造函数用来定义 ...