[poj2349]Arctic Network(最小生成树+贪心)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 17758 | Accepted: 5646 |
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
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
Source
#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(最小生成树+贪心)的更多相关文章
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- 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 ...
- POJ-2349 Arctic Network(最小生成树+减免路径)
http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...
- POJ 2349 Arctic Network(贪心 最小生成树)
题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...
- TZOJ 2415 Arctic Network(最小生成树第k小边)
描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...
- POJ2349 Arctic Network
原题链接 先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献. 显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除. 所以最后的答案就是 ...
随机推荐
- size_t 类型
1 关于size_t定义 size_t是一种数据相关的无符号类型,它被设计得足够大以便能够内存中任意对象的大小.在cstddef头文件中定义了size_t类型,这个文件是C标准库stddef.h头文件 ...
- c3p0连接池]
<c3p0-config> <!-- 默认配置 --> <default-config> <property name="jdbcUrl" ...
- activiti 里面各个方法理解
/** Return the intent that started this activity. */public Intent getIntent() { return mIntent;} pub ...
- Word2013中制作按钮控件
1.由于“开发工具”不经常用,所以在功能选项面板中没有“开发工具”这一栏.所以我们需要设置.在功能选项面板中选择“文件”,在跳转出来的版面中选择“选项”.
- shell: bad interpreter: No such file or directory
执行shell脚本 错误提示如下: bash: ./back : bad interpreter:No such file or directory 因为操作系统是windows,在win ...
- 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 第一个APP
参考博文: [Phonegap+Sencha Touch] 移动开发1.准备工作 [Phonegap+Sencha Touch] 移动开发2.PhoneGap/Cordova初步使用 经过差不多1 ...
- PHP基础班初学心得:脑洞实验-JS变量存储函数与return的一些问题
本人刚参加PHP基础班培训第一天,由于之前毫无基础,分享的心得可能不规范,方法也许也"旁门左道",不能保证质量,只作自己总结学习,也希望能帮助到同样是初学者的朋友们,共同进步. 在 ...
- express框架路由配置及congtroller自动加载
express框架在node官方推荐的一个框架,关于如何入门的文章,已经很多了,我就不在累赘了,本文的核心是如何修改文件使得更接近一个MVC的框架 express原生是通过require的方式实现了模 ...
- Win7下清除SQL SERVER 2008的SSMS保存的登录信息
C:\Users\{用户名}\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\
- Android 6.0 权限请求
在申请权限之前一定要在清单配置文件中添加该权限private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 1; //随便定义 publ ...