uva 10369 Arctic Network
题意:
有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星。两个基地之间可以通过卫星交流不管它们相距多远;但是通过无线电交流,就要求它们的距离不超过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的更多相关文章
- uva 10369 Arctic Network (最小生成树加丁点变形)
The Department of National Defence(DND)wishestoconnectseveral northern outposts by a wireless networ ...
- UVA 10369 - Arctic NetWork (求最小生成树)
题意: 在南极有 N 个科研站,要把这些站用卫星和无线电连接起来,是的任意两个之间都能互相通信,如果其中任意的一个地方安装了卫星,那么就可以和其他安装卫星的互相通信,和距离没有关系,但是安装无线电 ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- 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 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19113 Accepted: 6023 D ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
随机推荐
- 20165336 2017-2018-2 《Java程序设计》第4周学习总结
20165336 2017-2018-2 <Java程序设计>第4周学习总结 教材学习内容总结 第五章 使用extends来定义一个子类. Object类是所有类的祖先类. 当子类和父类不 ...
- python之文件操作的几种模式总结
文件操作的几种模式: "w" #write ,清空写,生成一个新的文件,写入内容,覆盖原文件"w+" ...
- 手工sql注入简单入门
1.判断是否可以注入: 数字型: 1.1在参数后面加一个引号',如果页面报数字number错误,则一定不是sql注入点:如果报数据库比如mysql.oracle之类的错误,则是一个sql注入点. 1. ...
- 遍历出文档内所有元素的tagName
//深度优先 function deepLogTagNames(parentNode){ console.log(parentNode.tagName); const childNodes=paren ...
- MTU 和 MSS 关系、 IP分片、TCP分段
从四层模型:链路层,网络层,传输层,应用层说 一 .以太网V2格式数据帧 : 链路层 Destination Source Type DataAndPad FCS 6 ...
- navicat如何导出mysql数据表结构
我们在创建数据库时会对字段进行设置,比如类型.长度等,如果字段多的话一个个设置非常麻烦,可以从其他地方已有的表导入数据表结构,怎么操作呢?我们拿navicat导出mysql数据表结构为例: 1.点击“ ...
- MySQL的nnodb引擎表数据分区存储
Symlinks are fully supported only for MyISAM tables. 对应Innodb引擎数据文件放到其他目录 mysql> SHOW VARIABLES L ...
- 前端框架之Vue(7)-事件处理
监听事件 可以用 v-on 指令监听 DOM 事件,并在触发时运行一些 JavaScript 代码. 示例: <div id="example-1"> <butt ...
- sap 类的左侧导航栏
- crm 理解
1:crm 就是一个 能够随时(通过labtop,mobile phone)掌握客户所有信息(过往的交易,)的工具. 通过足够的数据分析,能够更好的了解客户. 目的: a:使客户保留下来. b:赚取 ...