题意:

有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星。两个基地之间可以通过卫星交流不管它们相距多远;但是通过无线电交流,就要求它们的距离不超过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. Java之旅_面向对象_封装

    参考并摘自:http://www.runoob.com/java/java-encapsulation.html 在面向对象的程序设计方法中,封装(英语 :Encapsulation)是指一种将函数接 ...

  2. zip压缩类

    using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressi ...

  3. 【Selenium】selenium中隐藏元素如何定位?

    前言 面试题:selenium 中隐藏元素如何定位?这个是很多面试官喜欢问的一个题,如果单纯的定位的话,隐藏元素和普通不隐藏元素定位没啥区别,用正常定位方法就行了 但是吧~~~很多面试官自己都搞不清楚 ...

  4. 一个ajax请求,接收json数据

    <a id="inviterDel" onclick="delInviter(${item.inviterAddId})">删除</a> ...

  5. wps去广告

    彻底解决WPS弹出热点广告.WPS购物图标的办法 方法一:(一定有效) https://www.cnblogs.com/ytaozhao/p/5654149.html 一直用WPS,但一直有一个问题迟 ...

  6. 微信小程序分享支持自定义封面图

    微信小程序又发布更新了,刚好昨天支付宝也发布小程序,不能让它抢了风头的节奏.微信小程序主要更新如下:“小程序分享支持自定义封面图,公众号及小程序客服可发送小程序卡片.同时,我们还开放了获取发票抬头,指 ...

  7. Java中的枚举Enum

    public class TestEnum { /*最普通的枚举*/ public enum ColorSelect { red, green, yellow, blue; } /* 枚举也可以象一般 ...

  8. 通过thriftserver的beeline/jdbc等方式连接到SparkSQL

    thriftserver和beeline的简单配置和使用启动thriftserver: 默认端口是10000 ,可以修改 $ ./${SPARK_HOME}/sbin/start-thriftserv ...

  9. 282A

    #include <iostream> #include <string> using namespace std; int main() { int n, plus, sub ...

  10. 删除 clean tomcat7:run

    1.在eclipse中运行的绿色箭头旁边有个下箭头,点击: 2.选择Run Configurations... 3.在Maven Builder下删除不想要的