题意:

给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少。

分析:

s个卫星可以代替s-1条路, 所以只要求最小生成树, 排序后后去掉s-1条边, 最大那条就是答案。

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include <iomanip>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define _rep(i,a,b) for(int i = a; i <= b; i++)
#define mem(a,n) memset(a,n,sizeof(a))
#define fre(a) freopen(a,"r", stdin); typedef long long LL;
using namespace std;
const double inf = 1e9;
int T,s,p;
double p2p(double x1, double y1, double x2, double y2){ //距离可以需要时候再求出来
return sqrt((x1-x2) * (x1-x2) + (y1-y2)*(y1-y2));
}
double X[], Y[], dis[];
vector<int> G[];
bool vis[];
struct edge{
int u ,v;
double d;
edge(int _u,int _v, double _d):u(_u),v(_v),d (_d){};
};
bool cmp(edge a, edge b){
return a.d > b.d;
}
void prim(){
fill(dis, dis+, inf);
mem(vis,);
vis[] = ;
dis[] = ;
for(int i = ; i < G[].size(); i++){
int v = G[][i];
dis[v] = p2p(X[], Y[], X[v], Y[v]);
}
vector<double> ans;
set<int> in;
rep(times, , p-){
double min_dis = 1e9;
int pick = -;
_rep(i,,p){
if(!vis[i] && dis[i] < min_dis){
min_dis = dis[i], pick = i;
}
}
vis[pick] = ;
ans.push_back(min_dis);
// printf("min_dis : %.4f\n", min_dis);
rep(i,,G[pick].size()){
int v = G[pick][i];
double d = p2p(X[pick], Y[pick], X[v], Y[v]);
if(dis[v] > d) dis[v] = d;
}
} sort(ans.begin(), ans.end()); if(s < ){//如果小于2, 那么不能减少任意一条边
printf("%.2f\n", ans[ans.size() - ]);
return;
}
if(p - s - >= ans.size()) { //如果s - 1多于边的总数, 那么不用任何一条边
puts("");
}
else printf("%.2f\n", ans[p-s-]); //找出第s-1大的边 }
int main(){
cin >> T;
while(T--){
cin >> s >> p;
_rep(i,,p){
double x, y;
cin >> x >> y;
X[i] = x, Y[i] = y;
}
_rep(i,,p)_rep(j,i+,p){ //建一个完全图, 因为任意两点都是可达的
G[i].push_back(j);
G[j].push_back(i);
}
prim();
_rep(i,,p) G[i].clear();
mem(vis,);
mem(X,);
mem(Y,);
}
return ;
}

POJ 2349 Arctic Network(贪心 最小生成树)的更多相关文章

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

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

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

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

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

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

  4. poj 2349 Arctic Network

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

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

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

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

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

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

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

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

  9. poj 2349 Arctic Network 最小生成树,求第k大条边

    题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...

随机推荐

  1. Spring自动扫描注解类的冲突问题

    原文地址:http://www.blogjava.net/crazycy/archive/2014/07/12/415738.html Spring MVC项目中通常会有二个配置文件,spring-s ...

  2. Hdu 5451 Best Solver (2015 ACM/ICPC Asia Regional Shenyang Online) 暴力找循环节 + 递推

    题目链接: Hdu  5451  Best Solver 题目描述: 对于,给出x和mod,求y向下取整后取余mod的值为多少? 解题思路: x的取值为[1, 232],看到这个指数,我的心情是异常崩 ...

  3. Codeforces Round #402 (Div. 2) B

    Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...

  4. 146 LRU Cache 最近最少使用页面置换算法

    设计和实现一个  LRU(最近最少使用)缓存 数据结构,使它应该支持以下操作: get 和 put .get(key) - 如果密钥存在于缓存中,则获取密钥的值(总是正数),否则返回 -1.put(k ...

  5. PowerShell和Bash的介绍

    PowerShell是运行在windows平台的脚本,而Bash是运行在linux平台的脚本 现在bash能做的事情,PowerShell也能做,PowerShell的强大之处是它可以管理window ...

  6. 基于坐标的自动化测试神器---Total Control快速入门

    1.Total Control简单介绍 一款能够在PC上控制手机的软件,同时可以使用PC 触摸屏.鼠标.键盘, 全面操控 Android 手机,只需通过 USB 或 WiFi 连接手机至电脑,即可随时 ...

  7. 013、BOM对象的应用

    BOM结构图如下: DOM结构图如下: BOM和DOM BOM,Bowser Object Model浏览器对象模型.提供了访问和操作浏览器各组件的途径或方法. 比如:Navigator对象:浏览器的 ...

  8. mac下fiddler安装配置启动及iphone配置连接

    Getting started 下载安装Mono 如果没有下载则下载:https://www.mono-project.com/download/stable/#download-mac 从Mozil ...

  9. 【HEVC帧间预测论文】P1.4 Motion Vectors Merging: Low Complexity Prediction Unit Decision

    Motion Vectors Merging: Low Complexity Prediction Unit Decision Heuristic for the inter-Prediction o ...

  10. javascript动态添加、修改、删除对象的属性与方法

    在其他语言中,对象一旦生成,就不可更改了,要为一个对象添加修改成员必须要在对应的类中修改,并重新实例化,而且程序必须经过重新编译.JavaScript 中却非如此,它提供了灵活的机制来修改对象的行为, ...