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(二分+最小生成树)的更多相关文章

  1. POJ-2349 Arctic Network(最小生成树+减免路径)

    http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...

  2. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

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

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

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

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

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

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

  6. POJ2349 Arctic Network(Prim)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16968   Accepted: 5412 D ...

  7. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

  8. 【UVA 10369】 Arctic Network (最小生成树)

    [题意] 南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连.任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远. 而安装有无线电设备的两个站 ...

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

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

  10. POJ 2349 Arctic Network(最小生成树,第k大边权,基础)

    题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...

随机推荐

  1. python学习笔记04 --------------基本运算符

    1.算数运算 + 加 - 减 * 乘 /   除 % 取模(先做除法,然后返回余数) ** 乘方(幂运算) //          取整(相除,然后返回商的整数部分) 2.比较运算(返回布尔值) == ...

  2. python 终级篇 django ---ORM操作

                                       一般操作                                                          必会的 ...

  3. CSP201412-2:Z字形扫描

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  4. Android开发-API指南-<receiver>

    <receiver> 英文原文:http://developer.android.com/guide/topics/manifest/receiver-element.html 采集(更新 ...

  5. 【halcon】算子

    算子 rgb1_to_gray  灰度化 threshold:英文是阈的意思    二值化算子 Connection Compute connected components of a region. ...

  6. 1.EOS源码编译运行

    目前网络上都是针对老版EOS2.0源码编译的文章,我在mac上参考这些文章编译,最后发现根本就不对,最新版本只需一条命令(./eosio_build.sh,依赖库会自动安装的)即可.我根据这些文章手动 ...

  7. nodejs笔记--Events篇(二)

    常用事件 /* 调用events模块,获取events.EventEmitter对象 */ var EventEmitter = require('events').EventEmitter; var ...

  8. wf效能分析

    听从了老师的建议我请教了其他的同学,修改了代码实现了功能四,以下是我的效能测试: 1.采用ptime.exe测试的3次截图 可以看到的是三次执行时间分别为:1.449秒:0.915秒:0.871秒,取 ...

  9. 基于TensorFlow解决手写数字识别的Softmax方法、多层卷积网络方法和前馈神经网络方法

    一.基于TensorFlow的softmax回归模型解决手写字母识别问题 详细步骤如下: 1.加载MNIST数据: input_data.read_data_sets('MNIST_data',one ...

  10. 福大软工1816:Alpha(5/10)

    Alpha 冲刺 (5/10) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务: 文字/口头描述: 1.忙于复习,本次无成果 展示 ...