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

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

Source

 
题意:
在给定坐标系中有p个点,可以建s条边权为零的边连接任意两点,问要使所有点联通且边权之和最小,建的边权最大的权值
(算了还是看别人翻译吧)
最小生成树裸题,贪心的去掉最小生成树中最大的s条边即可
 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef struct{
int frm,to;
double dis;
}edge;
typedef struct{
int x,y;
}point;
edge gra[];
point poi[];
int fa[],num;
int fnd(int x){
return fa[x]==x?x:fnd(fa[x]);
}
int uni(int x,int y){
int fx=fnd(x);
int fy=fnd(y);
fa[fy]=fx;
return ;
}
int cmp(const edge &a,const edge &b){
return a.dis<b.dis;
}
int add(int frm,int to,double dis){
gra[++num].frm=frm;
gra[num].to=to;
gra[num].dis=dis;
return ;
}
double kru(int k){
int cnt=;
sort(gra+,gra+num+,cmp);
for(int i=;i<=num;i++){
int fx=fnd(gra[i].frm);
int fy=fnd(gra[i].to);
if(fx!=fy){
cnt++;
if(cnt==k){
return gra[i].dis;
}
uni(fx,fy);
}
}
return 0.0;
}
int main(){
int s,p,t;
scanf("%d",&t);
while(t--){
num=;
scanf("%d %d",&s,&p);
if(s==)s=;
for(int i=;i<=p;i++)scanf("%d %d",&poi[i].x,&poi[i].y);
for(int i=;i<=p;i++)fa[i]=i;
for(int i=;i<=p;i++){
for(int j=i+;j<=p;j++){
double dis=sqrt((double)((poi[i].x-poi[j].x)*(poi[i].x-poi[j].x)+(poi[i].y-poi[j].y)*(poi[i].y-poi[j].y)));
add(i,j,dis);
add(j,i,dis);
}
}
printf("%.2lf\n",kru(p-s));
}
return ;
}
 
 

[poj2349]Arctic Network(最小生成树+贪心)的更多相关文章

  1. poj2349 Arctic Network - 最小生成树

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

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

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

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

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

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

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

  5. POJ2349 Arctic Network(Prim)

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

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

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

  7. POJ 2349 Arctic Network(贪心 最小生成树)

    题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...

  8. TZOJ 2415 Arctic Network(最小生成树第k小边)

    描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...

  9. POJ2349 Arctic Network

    原题链接 先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献. 显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除. 所以最后的答案就是 ...

随机推荐

  1. Windows 服务为宿主的WCF服务,详细图解。

    废话不多说,直接进入主题: 1.打开vs2010新建项目,选择Windows服务. 2.选中WindowsService右击,添加WCF服务. 3.添加成功后,为下图.将接口类ITestService ...

  2. C# 文件压缩加解密

    1.这种方式也可以做到对文件的加密压缩,解密解压缩,只是在压缩和解压缩时会出现压缩窗口 1.1加密压缩 strzipPath:压缩包路径 strtxtPath:待压缩的文件路径 password:加密 ...

  3. (转)学习使用Jmeter做压力测试(一)--压力测试基本概念

    一.性能测试的概念 性能测试是通过自动化的测试工具模拟多种正常峰值及异常负载条件来对系统的各项性能指标进行测试.负载测试和压力测试都属于性能测试,两者可以结合进行. 通过负载测试,确定在各种工作负载下 ...

  4. People Tools catalog tables.

    People Tools catalog tables. Projects PSPROJECTDEFN — Project header table PSPROJECTITEM — Definitio ...

  5. select/poll/epoll on serial port

    In this article, I will use three asynchronous conferencing--select, poll and epoll on serial port t ...

  6. 关于firewalld防火墙的使用

    要想使用该防火墙,应该需要安装 networkmanager 并启动其服务.因为之前使用的是 netctl 提供的wifi-menu 来连接无线网络,导致安装networkmanager之后启动 Ne ...

  7. oracle细节

    1.oracle中NVL的含义: 如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值. 2.Oracle中in和exists的区别: 1).sel ...

  8. 二十三、Java基础--------网络编程

    Java中另一个重要技术就是网络编程了,为了更好的学习web方向的知识,有必要对java之网络编程好好学习,本文将围绕网络编程技术进行分析. 常见的网络协议:UDP.TCP UDP 1. 将数据源和目 ...

  9. javascript 创建 div

        纯JAVASCRIPPT创建 (1):document.getElementById("要创建DIV位置的ID").innerHTML='<div>div里面的 ...

  10. jade模板

    jade 模板使用 npm install jade -g      安装到全局 jade index.jade         导出一个 index.html 压缩后的 jade -P index. ...