题目链接: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. volatile 用法

    volatile 影响编译器编译的结果,指出,volatile 变量是随时可能发生变化的,与volatile变量有关的运算,不要进行编译优化,以免出错,(VC++ 在产生release版可执行码时会进 ...

  2. FOJ 2013 11 月赛

    这套题目还是比较吊的,由于我的沙茶,还是很多没有做出来- -! C:逆序数 D:呵呵 A:妈蛋,自己精度没弄好,想到之前GCC的要加eps,就WA了几次后交Visual C++过了!C(n,m)p^m ...

  3. 算法训练 区间k大数查询

    http://lx.lanqiao.org/problem.page?gpid=T11 算法训练 区间k大数查询   时间限制:1.0s   内存限制:256.0MB        问题描述 给定一个 ...

  4. MyEclipse 下 Tomcat启动变慢如何解决

    MyEclipse   下  Tomcat启动变慢如何解决 项目使用debug启动有时候会突然变得非常慢.不但启动慢,启动之后连打开项目页面也很慢,是日常的4,5倍.可以有下面的几种解决方法: 1. ...

  5. Android -- 自定义View小Demo,关于Rect绘制Android机器人(一)

    1,关于Rect和RectF类的区别以前一直没有去关注它,刚刚了解了一下才知道都是用来确定矩形的区域,不过Rect是int类型的坐标而RectF是float类型的坐标,所以说RectF要更加精确.现在 ...

  6. Android 测试Service的生命周期

    package com.example.myapp4; import android.support.v7.app.ActionBarActivity; import android.content. ...

  7. angular 解析html

    方法1:写filter <div ng-bind-html="showContent | html" class="detail-content"> ...

  8. CSS3 Transform Matrix

    css3中的transform让我们操作变形变得很简单,诸如,translate–移动,scale–缩放,rotate–旋转,skew–斜切.这几个属性很方便,也很简单,但是其中matrix我们就不常 ...

  9. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindowX 02

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindowX 02 procedure TForm1.Button1Click(Sender: TObject);var img : H ...

  10. sql server中index的REBUILD和REORGANIZE

    参考文献: http://technet.microsoft.com/en-us/library/ms188388.aspx 正文 本文主要讲解如何使用alter index来rebuild和reor ...