[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
原题链接 先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献. 显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除. 所以最后的答案就是 ...
随机推荐
- mpt_voronoi demo
% %demo1% A=rand(3,10);% pbound=Polyhedron([0 0 0;150 0 0;150 150 0;0 150 0; 0 0 1;150 0 1;150 150 1 ...
- python pymysql和orm
pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同. 1. 安装 管理员打开cmd,切换到python的安装路径,进入到Scripts目录下(如:C:\Users\A ...
- Timusoj 1982. Electrification Plan
http://acm.timus.ru/problem.aspx?space=1&num=1982 1982. Electrification Plan Time limit: 0.5 sec ...
- Json_异常_net.sf.json.JSONException: JSONObject["solution"] not found.
net.sf.json.JSONException: JSONObject["solution"] not found. 没有这个元素造成的. 问题代码: JSONObject j ...
- iOS解析XML数据
iOS中解析XML数据的类是 NSXMLParser,详细使用方法如下: 假设现在在内存中有XML的二进制数据对象(NSData):data(该数据可能来自网络,也可能是本地的文件数据),设置NSX ...
- Mysql的基础使用之MariaDB安装
初学mysql的小白,首次写博客,为了能让自己记得更加深刻,也是以一种小白的角度交代初学者的经历和困难,也算是记录自己成长的步伐吧 我首次用mysql是在ubuntu上 ,现在用的是linux 中的R ...
- 就最近学习MVC4.0的页面用法学到的东西
最近进了一家新公司,学习的东西还是蛮多的,首先了解的是@using(new Ajax.beginForm("",null,new AjaxOptions() { OnSuccess ...
- Ring buffers and queues
Ring buffers and queues The data structure is extremely simple: a bounded FIFO. One step up from pla ...
- exp_tools
#pwntools # github https://github.com/Gallopsled/pwntools 在线帮助文档 https://docs.pwntools.com/en/stable ...
- 09B-独立按键消抖实验02——小梅哥FPGA设计思想与验证方法视频教程配套文档
芯航线--普利斯队长精心奉献 实验目的: 1.复习按键的设计 2.用模块化设计的方式实现每次按下按键0,4个LED显示状态以二进制加法格式加1,每次按下按键1,4个LED显示状态以二进制加法格式减 ...