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的城市联络.题 ...
随机推荐
- [C++] Copy Control (part 1)
Copy, Assign, and Destroy When we define a class, we specify what happens when objects of the class ...
- Javascript闭包演示【转】
文章出自http://www.cnblogs.com/snandy/archive/2011/03/01/1967628.html 有个网友问了个问题,如下的html,为什么点击所有的段落p输出都是5 ...
- php常用方法汇总
xml格式转成array <?php $str='<xml><node><![CDATA[content]]></node></xml> ...
- C语言--链表基础模板
1.建立结构体 struct ST { int num;///学号 int score;///成绩 struct ST*next; };///结构体 2.空链表的创建 struct ST creatN ...
- mysql8基本配置,差点被各种坑蒙圈
1. 下载免安装版mysql地址 https://dev.mysql.com/downloads/mysql/ 2. 基本配置 (1)解压zip包,将bin目录添加到环境变量 (2)在mysql根目录 ...
- 运行jar
将Spring Boot 应用打包成jar, java -jar **.jar运行, 如果需要设置运行参数 java -jar **.jar --server.port=9080
- 第二章 IoC
什么是IoC 如何配置IOC Bean的生命周期 多环境配置 条件化配置Bean 什么是IOC? IOC有两层含义, 1.控制反转:将对象实例的创建与销毁的权限交给Spring容器管理,而不再是调用对 ...
- RT-thread国产实时操作系统概述
RT-Thread实时操作系统是一个分层的操作系统,它包括了: • 组件层components,这些是基于RT-Thread核心基础上的外围组件,把一些功能模块划分成独立的一个个组件模块,做到组件与组 ...
- Python Collections详解
Python Collections详解 collections模块在内置数据结构(list.tuple.dict.set)的基础上,提供了几个额外的数据结构:ChainMap.Counter.deq ...
- OpenStack Queens版本Horizon定制化开发
工具环境 1.VMware workstation 12+: 2.Ubuntu系统+Linux Pycharm: 3.OpenStack Queens版本Horizon代码: 问题及解决 1.项目代码 ...