poj2349:http://poj.org/problem?id=2349

题意:有卫星电台的城市之间可以任意联络。没有卫星电台的城市只能和距离小于等于D的城市联络。告诉你卫星电台的个数S,让你求最小的D.

题解: 生成最小生成树,去掉最长的S条边后,剩下最长的边就是D.也就是求最小生成树中第S+1长的边。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 100000000.0
using namespace std;
int cas,x,y,top;
int n,s;
double lowcost[],ans[],g[][];
struct Node{
int x;
int y;
}node[];
double juli(Node a,Node b ){
return sqrt(((double)a.x-b.x)*(a.x-b.x)+((double)a.y-b.y)*(a.y-b.y));
}
void prim(int v0){
top=;
for(int i=;i<=n;i++){
lowcost[i]=g[v0][i];
}
lowcost[v0]=-;
for(int i=;i<n;i++){
double min=INF;
int v=-;
for(int j=;j<=n;j++){
if(lowcost[j]!=-&&lowcost[j]<min){
min=lowcost[j];
v=j;
}
}
if(v!=-){
ans[top++]=lowcost[v];
lowcost[v]=-;
for(int k=;k<=n;k++){
if(lowcost[k]!=-&&g[v][k]<lowcost[k]){
lowcost[k]=g[v][k];
}
}
}
}
}
void solve(){
sort(ans,ans+top);
printf("%.2f\n",ans[top-s]);
}
int main(){
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&s,&n);
for(int i=;i<=n;i++){
scanf("%d %d",&node[i].x,&node[i].y);
}
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
g[i][j]=g[j][i]=juli(node[i],node[j]);
// printf("%.2f\n",g[i][j]);
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
if(i==j)g[i][j]=;
else if(g[i][j]==)g[i][j]=INF;
}
prim();
solve();
}
}

Arctic Network的更多相关文章

  1. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  2. 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 ...

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

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

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

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  5. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  6. POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19113   Accepted: 6023 D ...

  7. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  8. POJ2349 Arctic Network(Prim)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16968   Accepted: 5412 D ...

  9. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  10. G - Arctic Network

    G - Arctic Network   #include<cmath> #include<cstdio> #include<cstring> #include&l ...

随机推荐

  1. libcurl使用演示样例

    简要说明:C++使用libcurl訪问"www.baidu.com".获取返回码和打印出http文件 /* * @ libcurl使用演示样例 * @ 2014.04.29 * @ ...

  2. 摄像头参数查看与调节 分类: C/C++ OpenCV 2014-11-08 18:13 138人阅读 评论(0) 收藏

    cvGetCaptureProperty 获得视频获取结构的属性 double cvGetCaptureProperty( CvCapture* capture, int property_id ); ...

  3. hdu 3720 Arranging Your Team 枚举

    不可能解可以直接判断. 搭配产生的附加分可以用一个二维数组保存. 枚举1442,4种类型的人,因为总人数只有23个,所以可以搜索暴力枚举,然后保存最优解. 注意trick,答案可能为负数,所以初始化a ...

  4. ZYKeyboardUtil 全自动处理键盘遮挡事件

    键盘遮盖输入控件或按钮在日常app开发中避之不及,考虑各种情况下UI各种嵌套,最后还要注册监听再获取指定键盘信息.我们可以通过键盘处理工具类ZYKeyboardUtil避繁就简,利用Block的方式处 ...

  5. shell脚本实现冒泡排序 分类: 学习笔记 linux ubuntu 2015-07-10 14:16 79人阅读 评论(0) 收藏

    手动输入一行字符串,并对其排序. 脚本如下: #!/bin/bash #a test about sort echo "please input a number list" re ...

  6. Sql2008中使用DataTable作为存储过程的参数

    使用DataTable作为存储过程的参数   最近工作中写了几个存储过 程,需要向存储过程中传递字符串,因为SQL Server 2000中没有内置类似于 split 的函数,只好自己处理,将前台数据 ...

  7. sql - 以半月,每月 分组

    按半月:完整代码: SELECT siteNumber [站点], CONVERT(VARCHAR(7),day,120)+'-'+ case when day(day) between 1 and ...

  8. wsdlLocation可以写成项目的相对路劲吗

    如果客户端的代码使用wsdl生成的话,这个地址是从wsdl描述的<service>里的<location>获取的,如果开发过程中服务地址换了,那只能手工来修改了,好像只有一个地 ...

  9. ORACLE 中ROWNUM用法总结!(转)

    对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between...and,只能用以上符号(<.<=.!=),并非说用>,>=,=,be ...

  10. OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

    1.安装Homebrew,执行命令 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...