POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349
Description
Any two outposts with a satellite channel can communicate via the
satellite, regardless of their location. Otherwise, two outposts can
communicate by radio only if the distance between them does not exceed
D, which depends of the power of the transceivers. Higher power yields
higher D but costs more. Due to purchasing and maintenance
considerations, the transceivers at the outposts must be identical; that
is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the
transceivers. There must be at least one communication path (direct or
indirect) between every pair of outposts.
Input
first line of input contains N, the number of test cases. The first
line of each test case contains 1 <= S <= 100, the number of
satellite channels, and S < P <= 500, the number of outposts. P
lines follow, giving the (x,y) coordinates of each outpost in km
(coordinates are integers between 0 and 10,000).
Output
each case, output should consist of a single line giving the minimum D
required to connect the network. Output should be specified to 2 decimal
points.
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
/*
问题
题目理解起来有一定的难度,理解了就是水题一道。怎么理解呢?就是一遍一遍的读。
重要的是每个顶点会配备一个无线接收器,其中一些顶点还会配备一个卫星信道。现在给出卫星信道的个数和顶点个数以及每个顶点的坐标,
问使用卫星通道和接收器使得接收器的工作范围尽可能的小,因为卫星通道可以直接通信。 解题思路
刚开始读题的时候以为要消去s条边,结果计算样例的结果是200,其实是卫星信道的个数,换句换说每两个卫星信道才可以消去一条边。 处
理每两点之间的边,使用克鲁斯卡尔算法一条一条的加入,直至加入的这条边是第p-s条边时结束。因为一共需要p-1条边而使用s个卫星接收
信道可以使s-1条边免费,所以只需p-1-(s-1)即p-s条边即可。
*/
#include<cstdio>
#include<math.h>
#include<algorithm> using namespace std;
struct NODE{
int x,y;
}node[]; struct EDGE{
int u,v;
double w;
}edge[]; int cmp(struct EDGE a,struct EDGE b){
return a.w<b.w;
}
int f[];
int merge(int v,int u);
int getf(int v);
int main()
{
int t,s,p,i,j,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&s,&p);
for(i=;i<=p;i++){
scanf("%d%d",&node[i].x,&node[i].y);
} k=;
for(i=;i<=p-;i++){
for(j=i+;j<=p;j++){
edge[k].u=i;
edge[k].v=j;
edge[k].w=sqrt(1.0*(node[i].x-node[j].x)*(node[i].x-node[j].x) +
1.0*(node[i].y-node[j].y)*(node[i].y-node[j].y));
}
}
sort(edge,edge+k,cmp); /*for(i=0;i<k;i++)
printf("%lf\n",edge[i].w);*/ for(i=;i<=p;i++)
f[i]=i; int cou=;
for(i=;i<k;i++){
if(merge(edge[i].u,edge[i].v)){
//printf("选择了第%d这条边%.2lf\n",i,edge[i].w);
cou++;
}
if(cou == p-s){
printf("%.2lf\n",edge[i].w);
break;
}
}
}
return ;
} int getf(int v)
{
return f[v]==v?v:f[v]=getf(f[v]);
} int merge(int v,int u)
{
int t1,t2;
t1=getf(v);
t2=getf(u);
if(t1 != t2){
f[t2]=t1;
return ;
}
return ;
}
POJ 2349 Arctic Network(最小生成树中第s大的边)的更多相关文章
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 2349 Arctic Network 最小生成树,求第k大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于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(贪心 最小生成树)
题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...
随机推荐
- [php-pear]如何使用 PHP-PEAR安装器,以及使用 PEAR 安装扩展库
我们都知道 PHP PEAR,就是 PHP Extension and Application Respository,也就是 PHP 扩展和应用代码库. PHP 也可以通过 PEAR 安装器来进行 ...
- [leetcode 120]triangle 空间O(n)算法
1 题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjac ...
- datetime & time
python有两个和时间相关的模块,datetime和time datetime datetime模块下有四个类 date 日期相关的 time 时间相关的 datetime ...
- 基于tkinter的九型人格测试系统介绍
基于tkinter的九型人格测试系统介绍 一.程序代码地址,GitHub 二.程序介绍 1.login.py 登录界面: 注册界面: 2.mainWindow.py 登录成功之后的界面: 3.doTe ...
- 多个SpringMVC项目配置统一管理(来自于springCloud的统一配置思路)
因公司项目分多个系统进行开发,而系统架构几乎完全一样,所以同样的配置文件会存在不同的系统中 当其中的某些配置需要修改时,就需要依次把所有系统中相关的配置都修改掉 纯耗时且没技术含量的体力活 所以借鉴S ...
- Python-flask跨站请求伪造和跨站请求保护的实现
图中 Browse 是浏览器,WebServerA 是受信任网站/被攻击网站 A,WebServerB 是恶意网站/点击网站 B. (1) 一开始用户打开浏览器,访问受信任网站 A,输入用户名和密码登 ...
- iOS-发送短信验证码倒计时
/** 发送手机验证码 */ -(void)startSenderYzmMessage{ __block ; //倒计时时间 dispatch_queue_t queue = dispatch_get ...
- asp.net core中遇到需要自定义数据包解密方法的时候
最近将公司的项目用.netcore重写, 服务的http外部接口部分收发消息是DES加解密的, 那么在asp.net core mvc的action处理之前需要加入解密这个步骤. 我第一想到的是用fi ...
- (转)Python3之requests模块
原文:https://www.cnblogs.com/wang-yc/p/5623711.html Python标准库中提供了:urllib等模块以供Http请求,但是,它的 API 太渣了.它是为另 ...
- (转)Python 日志处理(三) 日志状态码分析、浏览器分析
原文:https://www.cnblogs.com/i-honey/p/7791564.html 在企业中,从日志中提取数据进行分析,可以帮助企业更加了解用户行为,用户最感兴趣的产品或者内容,分析得 ...