题目链接:http://poj.org/problem?id=2349

Arctic Network
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 17032   Accepted: 5441

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

 
题意:1案例数,2个点是可以用无线的(用无线的点,到任何点的距离不受限制),4个点,下面是坐标,求最小生成树中的最大权值,和之前的不同点是在权值为0的点是不确定的。
思路:照样求最小生成树,有2个点的距离为0,即可以在最小生成树中删掉两条最长的边。最靠后的那条边就是最大的权值。
#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),最小生成树的变形的更多相关文章

  1. poj 2349(最小生成树应用)

    题目链接:http://poj.org/problem?id=2349 思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接 ...

  2. Arctic Network POJ 2349 (最小生成树思想)

    Description The Department of National Defence (DND) wishes to connect several northern outposts by ...

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

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

  4. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  5. POJ 2349 Arctic Network(最小生成树+求第k大边)

    题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...

  6. poj 2349 Arctic Network(最小生成树的第k大边证明)

    题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...

  7. POJ 2349 Arctic Network(最小生成树中第s大的边)

    题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...

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

    链接: http://poj.org/problem?id=2349 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1371 ...

  9. POJ 2349 Arctic Network(最小生成树,第k大边权,基础)

    题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...

随机推荐

  1. Lintcode: Expression Evaluation (Basic Calculator III)

    Given an expression string array, return the final result of this expression Have you met this quest ...

  2. @perproty and @synthesize

    .@property 是什么? @perperty 是声明属性的语法,他可以快速方便的为实例变量创建存取器,并允许我们通过点语法使用存取器 [存取器:用于获取和设置实例变量的方法,获取实例变量值得是g ...

  3. .NET: C#: StopWatch

    StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very ...

  4. hdu5255 魔法因子

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5255 首先先预处理出一个p,使得p*因子X等于一个整数,且p最小,设q=p*X. 则题目则可以看成存在 ...

  5. jsformat插件

    Package Control Package Control 是用来管理 Sublime Text 2 的插件的插件. 也是装完后第一个要安装的插件. 首先打开 ctrl+`, 并在打开的 st2 ...

  6. Android设计模式---观察者模式小demo(一)

    1,今天刚好看到了设计模式这一块来,而观察者模式是我一直想总结的,先来看看观察者模式的简单的定义吧 "当一个对象改变时,他的所有依赖者都会受到通知,并自动更新." 一般我们项目中就 ...

  7. JAVA测试装饰者模式

    package shb.java.demo; /** * 测试装饰者模式 * @package :shb.java.demoJava02 * @author shaobn * @Describe : ...

  8. 基于fullpage的幻灯片播放

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...

  9. oracle的会话(session)

    会话(session)是oracle服务器对数据库连接用户记录的一种手段. oracle提供了v_$session的视图存储当前数据库的会话,查询时用v_$session 或v$session sql ...

  10. jquery表格仿菜单

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...