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的城市联络.题 ...
随机推荐
- 研究实验1_搭建一个精简的C语言开发环境(包含部分经典的前言)
综合研究: 在这部分内容中,将启示我们如何进行独立研究和深度思考(一定要注意这一点,相应的调整自己的学习思想).同时使我们: (1)认识到汇编语言对于深入理解其他领域知识的 ...
- Undefined symbols “_OBJC_CLASS_$_XXX” 问题
解决方法是点击工程,在targets界面中找到Build Phases,根据提示信息“XXX”来判断缺少什么文件,一般如果缺少自定义的文件,XXX会是缺少的类名,那么就在Complie Sources ...
- 事件监听addEventListener()和removeEventListener() ---------1
一直想写一个原生事件监听的记录,方便以后看,不愿意写主要是事件监听的单词太长,记起来好难记每次都要查,这次把知道的写完了,来这里查好了,以后要是理解的更透彻了,就再补全好了 首先,DOM0级事件和DO ...
- 基于Qt实现的截图小程序
在最近做的行人检测项目中,由于需要训练分类器,而分类器的训练又需要有一个一定长宽的样本.为了方便样本的采集,因此实现了这样的一个截图程序.该程序的主要功能是加载视频到程序中,程序可以对视频进行播放.暂 ...
- SQL 2008 数据库只读 修改
先对数据库分离 数据库鼠标右键->任务->分离 将UsersDB.mdf UsersDB_log.LDF文件 属性->安全->编辑 两个文件的都要更改权限 ...
- Python学习总结19:类(一)
在Python中,可以通过class关键字定义自己的类,通过类私有方法“__init__”进行初始化.可以通过自定义的类对象类创建实例对象. class Student(object): count ...
- run()和star()区别
run()和star()区别 run()-->只是thread类的一个普通方法调用 star()-->用来启动线程,实现多线程运行
- Android 利用Service BroadcastReceiver实现小例子
Activity: package com.example.test; import android.app.Activity; import android.content.Context; imp ...
- JQuery书写Ajax的几种方式?
1 $.ajax({ type: "Post", //请求方式 ("POST" 或 "GET"), 默认为 "GET" ...
- 机器学习(Machine Learning)&深入学习(Deep Learning)资料
<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost 到随机森林. ...