题意:

有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星。两个基地之间可以通过卫星交流不管它们相距多远;但是通过无线电交流,就要求它们的距离不超过D。为了方便布置,节省成本,每个基地的无线电交流的最大距离都相等。给出基地的位置和卫星的数量,求出D,保证两个基地之间至少一个交流路径。

思路:

求出MST,保证了两点之间有路径,然后按照从大到小的顺序给在生成树中的边排序,将卫星安排给权值大的边,保证D尽可能小。s个卫星可以安排给s-1条边(s个点),所以第s条边的权值就是所求。克鲁斯卡尔算法,复杂度mlog(m)。

代码:

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std; const int N = ; struct edge
{
int x,y;
double cost; edge(int a,int b,double c)
{
x = a;
y = b;
cost = c;
}
}; int px[N],py[N];
int par[N]; vector<edge> es;
vector<double> vd; double cal(int i,int j)
{
double x2 = (px[i] - px[j]) * (px[i] - px[j]);
double y2 = (py[i] - py[j]) * (py[i] - py[j]); return sqrt(x2 + y2);
} bool cmp(edge a,edge b)
{
return a.cost < b.cost;
} int fin(int x)
{
if (x == par[x]) return x;
else return par[x] = fin(par[x]);
} void unit(int x,int y)
{
x = fin(x);
y = fin(y); if (x == y) return; par[x] = y;
} bool comp(double a,double b)
{
return a > b;
} int main()
{
int t; scanf("%d",&t); while (t--)
{
int s,n; es.clear(); vd.clear(); scanf("%d%d",&s,&n); for (int i = ;i <= n;i++) par[i] = i; for (int i = ;i < n;i++)
{
scanf("%d%d",&px[i],&py[i]);
} for (int i = ;i < n;i++)
{
for (int j = i + ;j < n;j++)
{
double len = cal(i,j); es.push_back(edge(i,j,len));
}
} sort(es.begin(),es.end(),cmp); for (int i = ;i < es.size();i++)
{
int x = es[i].x,y = es[i].y; if (fin(x) == fin(y)) continue; unit(x,y); vd.push_back(es[i].cost);
} sort(vd.begin(),vd.end(),comp); double ans = ; printf("%.2f\n",vd[s-]);
} return ;
}

uva 10369 Arctic Network的更多相关文章

  1. uva 10369 Arctic Network (最小生成树加丁点变形)

    The Department of National Defence(DND)wishestoconnectseveral northern outposts by a wireless networ ...

  2. UVA 10369 - Arctic NetWork (求最小生成树)

    题意: 在南极有  N  个科研站,要把这些站用卫星和无线电连接起来,是的任意两个之间都能互相通信,如果其中任意的一个地方安装了卫星,那么就可以和其他安装卫星的互相通信,和距离没有关系,但是安装无线电 ...

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

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

  4. 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 ...

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

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

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

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  7. poj 2349 Arctic Network

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

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

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

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

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

随机推荐

  1. selenium+iframe 如何定位元素(实战)

    场景: 在同一界面,需定位iframe里面的元素, 就需要切换至Iframe块,然后定位元素,验证完成后,再切换出来. 如果不切换至iframe ,会发现不管采取什么定位,都会报元素不存在.

  2. 【Python全栈-数据库】数据库基础

    数据库的简介 数据库 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据库中的数据按一定的数学模型组织.描述和存储,具有较小的冗余,较高的数据独立性和易扩展性, ...

  3. js对json格式对象进行增加,修改,删除

    // 假设数据为data var data=[ { "ID":"83d349de-eca4-4974-a8a7-f9b44b48c6f2", "IsL ...

  4. file 选取文件/文件夹

    一般网页上传文件大家都会用到这个标签 <input type="file" id="file_input"/> 我们可以通过这个标签选取文件,使用j ...

  5. oracle sqlplus login.sql设置

    sqlplus在启动时会自动运行两个脚本:glogin.sql.login.sql这两个文件 执行顺序为 1.默认在在$ORACLE_HOME/sqlplus/admin路径下查找glogin.sql ...

  6. mysql触发器:插入数据前更新创建时间为服务器的时间

    DROP TRIGGER IF EXISTS `upd_patientquestionnaire`; create trigger upd_patientquestionnaire BEFORE in ...

  7. (5.1)sql server系统数据库

    关键词:mssql系统数据库,sql server系统数据库,tempdb的作用 master:它包含一个系统表集合,是整个实例的中央存储库,维护登录账户,其他数据库,文件分布,系统配置设置,磁盘空间 ...

  8. MySQL无损复制(转)

    MySQL5.7新特性:lossless replication 无损复制 https://dev.mysql.com/doc/refman/5.7/en/replication-semisync.h ...

  9. APK反编译、重编译、签名、查看源码

    1.反编译与重编译 工具:apktool 下载地址:https://ibotpeaches.github.io/Apktool/ 环境:Java (JRE 1.7) 安装步骤:参考官网(也可以不安装, ...

  10. oracle安装---yum.sh

    !#/bin/bash yum install binutils* -yyum install compat* -yyum install elfutils* -yyum install gcc* - ...