POJ2349:Arctic Network(二分+最小生成树)
Arctic Network
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 28311 | Accepted: 8570 |
题目链接:http://poj.org/problem?id=2349
Description:
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
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:
The 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:
For 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
题意:
有n个点,现在有s个无线通话器,拥有无线通话器的不同点可以直接通信,但其余的通信只能在一个距离D内。
现在求这个最小D是多少。
题解:
问最小D,虽然点很少,但很明显直接枚举是不可行的。所以我们可以考虑二分这个距离D。
为什么可以二分?因为很明显地,这个距离D越大,可以直接通信的人也就越多,也就是这个问题是具有单调性的。
然后二分过后建图跑最小生成树看看有多少连通块,根据连通块个数来确定无线通话器的分配个数就行了。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = ;
int t;
int s,n,tot;
struct Point{
int x,y;
}p[N];
struct Edge{
int u,v;
double w;
bool operator < (const Edge &A)const{
return w<A.w;
}
}e[N*N];
int f[N];
int find(int x){
return f[x]==x?f[x]:f[x]=find(f[x]);
}
void Kruskal(){
for(int i=;i<=n+;i++) f[i]=i;
for(int i=;i<=tot;i++){
int fx=find(e[i].u),fy=find(e[i].v);
if(fx==fy) continue ;
f[fx]=fy;
}
}
double dis(int x,int y){
return sqrt((double)(p[x].x-p[y].x)*(p[x].x-p[y].x)+(double)(p[x].y-p[y].y)*(p[x].y-p[y].y));
}
void build(double x){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) continue ;
if(dis(i,j)<=x){
e[++tot].u=i;
e[tot].v=j;
e[tot].w=dis(i,j);
}
}
}
}
bool check(double x){
tot=;
build(x);
Kruskal();
int cnt = ;
for(int i=;i<=n;i++){
if(f[i]==i) cnt++;
}
if(s>=cnt) return true;
return false;
}
int main(){
cin>>t;
while(t--){
scanf("%d%d",&s,&n);
for(int i=;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
double l=,r=INF,mid;
while(r-l>=0.00001){
mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid+0.0001;
}
printf("%.2f\n",l);
}
return ;
}
POJ2349:Arctic Network(二分+最小生成树)的更多相关文章
- POJ-2349 Arctic Network(最小生成树+减免路径)
http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- 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(Prim)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16968 Accepted: 5412 D ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- 【UVA 10369】 Arctic Network (最小生成树)
[题意] 南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连.任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远. 而安装有无线电设备的两个站 ...
- uva 10369 Arctic Network (最小生成树加丁点变形)
The Department of National Defence(DND)wishestoconnectseveral northern outposts by a wireless networ ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
随机推荐
- 【system.file】使用说明
对象:system.file 说明:提供一系列针对文件操作的方法. 注意:参数中的filePath 均为相对网站根目录路径 目录: 方法 返回 说明 system.file.exists(filePa ...
- ntp服务:实现时间同步
一. 引言 目前的项目为分布式系统,采用dubbo+zookeepe,排查BUG,发现各个服务器的时间不一致,遂网上查找资源,使得时间保持一致. 二. 步骤 1)以第一台服务器为“服务端”,其他台服务 ...
- Paper Reading - Learning to Evaluate Image Captioning ( CVPR 2018 ) ★
Link of the Paper: https://arxiv.org/abs/1806.06422 Innovations: The authors propose a novel learnin ...
- StreamReader和StreamWriter中文乱码问题
StreamReader和StreamWriter中文乱码问题 1.写入: string FilePath = @"E:\Measure.csv"; StreamWriter w ...
- python3中使用python2中cmp函数出现错误
在python2中我们经常会使用cmp函数来比较一些东西,但是在python3中,你再来使用这个函数的时候,发现就报错了,提示找不到这个函数,这是为啥呢? 答:新版的python已经舍弃这种用法 而在 ...
- HADOOP/HDFS Essay
HDFS架构 the core of HADOOP/distributed systems is storeage(HDFS) and resource manager(YARN) for compu ...
- eos开发指南
十分钟教你开发EOS智能合约 在CSDN.柏链道捷(PDJ Education).HelloEOS.中关村区块链产业联盟主办的「EOS入门及最新技术解读」专场沙龙上,柏链道捷(PDJ Educatio ...
- java面试整理
IO和NIO的区别 这是一个很常见的问题,如果单纯的只回答IO和NIO的区别,只能算及格.我个人觉得应该从以下几个方面回答: 1).IO简介, 2).TCP的三次握手,因为这也是两者的区别之一, 3) ...
- 最小生成树——prim
prim:逐“点”生成最小生成树 与Dijkstra不同的是:加入点到生成树中,不要考虑与源点的距离,而是考虑与生成树的距离 #include <iostream> #include &l ...
- Scrum1
Scrum1 组员 任务分工 贡献 林泽宇 团队分工.撰写博客.修改完善需求规格说明书.整理代码规范 李涵 后端架构设计 尹海川 logo设计修改.数据库数据 郏敏杰 课堂展示.查阅资料.整理关键和难 ...