Poj(2349),最小生成树的变形
题目链接:http://poj.org/problem?id=2349
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 17032 | Accepted: 5441 |
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 <string.h>
#include <algorithm>
#include <math.h> using namespace std; int x[];
int y[]; struct Edge {
int u,v;
double w;
}edge[*]; int father[]; int Find_Set(int x)
{
if(x!=father[x])
father[x] = Find_Set(father[x]);
return father[x];
} int cmp (Edge a,Edge b)
{
return a.w < b.w;
} double ans[]; int main()
{
//freopen("input.txt","r",stdin);
int cases;
scanf("%d",&cases);
while(cases--)
{
memset(ans,,sizeof(ans));
int s,n;
scanf("%d%d",&s,&n);
for(int i=;i<n;i++)
scanf("%d%d",&x[i],&y[i]); int cnt = ;
for(int i=;i<n;i++)
for(int j=;j<i;j++)
{
edge[cnt].u = i;
edge[cnt].v = j;
edge[cnt++].w = sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]));
} for(int i=;i<=n;i++)
father[i] = i; sort(edge,edge+cnt,cmp); int k=;
for(int i=;i<cnt;i++)
{
int fx = Find_Set(edge[i].u);
int fy = Find_Set(edge[i].v);
if(fx!=fy)
{
father[fy] = fx;
ans[k]=edge[i].w;
k++;
if(k==n-)
break;
}
}
printf("%.2lf\n",ans[n-s-]);
}
return ;
}
Poj(2349),最小生成树的变形的更多相关文章
- poj 2349(最小生成树应用)
题目链接:http://poj.org/problem?id=2349 思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接 ...
- Arctic Network POJ 2349 (最小生成树思想)
Description The Department of National Defence (DND) wishes to connect several northern outposts by ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...
- (最小生成树) Arctic Network -- POJ --2349
链接: http://poj.org/problem?id=2349 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1371 ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
随机推荐
- Lintcode: Expression Evaluation (Basic Calculator III)
Given an expression string array, return the final result of this expression Have you met this quest ...
- @perproty and @synthesize
.@property 是什么? @perperty 是声明属性的语法,他可以快速方便的为实例变量创建存取器,并允许我们通过点语法使用存取器 [存取器:用于获取和设置实例变量的方法,获取实例变量值得是g ...
- .NET: C#: StopWatch
StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very ...
- hdu5255 魔法因子
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5255 首先先预处理出一个p,使得p*因子X等于一个整数,且p最小,设q=p*X. 则题目则可以看成存在 ...
- jsformat插件
Package Control Package Control 是用来管理 Sublime Text 2 的插件的插件. 也是装完后第一个要安装的插件. 首先打开 ctrl+`, 并在打开的 st2 ...
- Android设计模式---观察者模式小demo(一)
1,今天刚好看到了设计模式这一块来,而观察者模式是我一直想总结的,先来看看观察者模式的简单的定义吧 "当一个对象改变时,他的所有依赖者都会受到通知,并自动更新." 一般我们项目中就 ...
- JAVA测试装饰者模式
package shb.java.demo; /** * 测试装饰者模式 * @package :shb.java.demoJava02 * @author shaobn * @Describe : ...
- 基于fullpage的幻灯片播放
<!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...
- oracle的会话(session)
会话(session)是oracle服务器对数据库连接用户记录的一种手段. oracle提供了v_$session的视图存储当前数据库的会话,查询时用v_$session 或v$session sql ...
- jquery表格仿菜单
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...