poj 2349 Arctic Network 最小生成树,求第k大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高。
输入的数据意思:
实例个数
卫星个数 站点个数
每个站点的坐标
输出的意思:
发射器最小是多少,保留两位小数
注意事项:
其中卫星数量少于站点,存边的数组下标从0开始的,还有一个坑坑,输出用的.2f,而喜欢用.2lf的我错了四发才发现....
代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue> using namespace std; const int N = ;
double INF = 0x3f3f3f3f3f3f;
double cost[N][N],used[N];
bool visit[N];
double lowc[N];
int c;
bool cmp(double a,double b)
{
return a>b;
}
void Prim(int n)
{
memset(visit,false,sizeof(visit));
visit[] = true;
for(int i = ; i < n; i++) lowc[i] = cost[][i];
for(int i = ; i < n; i++)
{
double minc = 1.0*INF;
int p = -;
for(int j = ; j < n; j++)
{
if(!visit[j] && minc - lowc[j] > 1e-)
{
minc = lowc[j];
p = j;
}
}
visit[p] = true;
used[c++]= minc;
for(int j = ; j < n; j++)
{
if(!visit[j] && lowc[j] - cost[p][j] > 1e-)
lowc[j] = cost[p][j];
}
}
}
struct nodes
{
double x,y;
}point[N]; int main(void)
{
int i,j,t,m,n;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
for(i = ; i < n; i++)
scanf("%lf %lf",&point[i].x,&point[i].y);
for(i = ; i < n; i++)
for(j = ; j < n; j++)
cost[i][j] = cost[j][i] = INF; for(i = ; i < n; i++)
for(j = i + ; j <n; j++)
{
double temp = sqrt( (point[i].x-point[j].x)*(point[i].x-point[j].x) +(point[i].y-point[j].y)*(point[i].y-point[j].y));
cost[i][j] = cost[j][i] = temp;
}
memset(used,,sizeof(used));
c = ;
Prim(n);
sort(used,used+c,cmp);
printf("%.2f\n",used[m-]);//.2f神坑
}
return ;
}
poj 2349 Arctic Network 最小生成树,求第k大条边的更多相关文章
- 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 (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 2985 Treap平衡树(求第k大的元素)
这题也能够用树状数组做,并且树状数组姿势更加优美.代码更加少,只是这个Treap树就是求第K大元素的专家--所以速度比較快. 这个也是从那本红书上拿的模板--自己找了资料百度了好久,才理解这个Trea ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
- POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...
随机推荐
- [记录]学习树莓派3B接DHT11和LCD1602和修改树莓派时区
前提 树莓派系统安装好 apache web 服务器,如未安装,可在树莓派内执行sudo apt-get install apache2 进行安装apache 也可以通过命令获取GPIO信息: gpi ...
- 廖雪峰Java11多线程编程-3高级concurrent包-5Atomic
Atomic java.util.concurrent.atomic提供了一组原子类型操作: 如AtomicInteger提供了 int addAndGet(int delta) int increm ...
- JUC 一 Callable
java.util.concurrent.Callable是一个泛型接口,只有一个call()方法 Callable和Runnable的区别 Callable使用call()方法,Runnable使用 ...
- 容斥原理——poj1091
将m质因子分解,然后枚举选取的质因子个数i进行容斥,每种情况进行一次dfs即可 dfs结束标记:当质因子个数达到i时退出递归,同时累加该解对应的方案数 /* 给定n,m 共有n个数的数组a,不超过m ...
- sqlite3加密
最近因为工作原因,需要使用sqlite数据库.sqlite数据库小并且使用方便,感觉挺不错的.但有一个不足就是没有对数据库进行加密,不过好的是sqlite预留有加密的接口,我们可以直接调用即可.我也是 ...
- 服务器迁移部署PosApp
绑定 基本配置 高级设置
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 在Linux中使用selenium(环境部署)
1.安装chrome 用下面的命令安装Google Chrome yum install https://dl.google.com/linux/direct/google-chrome-stable ...
- CAS增加免登陆(Remember Me)功能
1. 打开deployerConfigContext.xml 在 authenticationManager 的bean中增加 <property name="authenticati ...
- 打开springboot的run dashboard
默认情况下,idea的run dashboard是关闭的,当检测到你有多个springboot项目时会弹出提示框,询问是否打开. 如果我们想要自己打开,需要修改配置. 在你的idea的项目目录中,有一 ...