题意:

给定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. 交表(Send a Table)

    #include<stdio.h> #include<string.h> #define N 50010 int phi[N],n,sum[N]; void phi_table ...

  2. nginx上游模块

    1 概念 The ngx_http_upstream_module is used to define groups of servers that can be referenced by the  ...

  3. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) A

    Description Bear Limak wants to become the largest of bears, or at least to become larger than his b ...

  4. 洛谷 P3960 列队

    https://www.luogu.org/problemnew/show/P3960 常数超大的treap #pragma GCC optimize("Ofast") #incl ...

  5. 记录Jmeter集成Jenkins运行Ant做接口监听

    最近在鼓捣Jmeter的接口测试,把他集成到了Jenkins上做自动化接口监听.把操作记录下来. 首先就是进行接口测试的编写.打开Jmeter.主要是把接口的测试逻辑和断言处理调通后就OK了,接口程序 ...

  6. 面试王牌 JAVA并发

    Java 并发 JavathreadSocketC#C++ 并发 Table of Contents 1 什么是并发问题. 2多线程死锁问题 2 java中synchronized的用法 3 Java ...

  7. 抽象类 abstract

    抽象类就是拿来继承的抽象方法就是拿来重写的 1.用abstract可以用来修饰类或方法,分别叫抽象类和抽象方法. 2.含有抽象方法的类必须被声明为抽象类.,抽象类必须被继承,抽象方法也必须被重写. 3 ...

  8. javaFx 学习笔记

    1.每个javaFx程序定义在一个继承自javafx.application.Application的类中 Button:用于设置一个按钮,Button btOK = new Button(" ...

  9. php数组与字符串转换

    1.将字符串转换成数组的几个函数: (1)explode(separate,string) 示例:$str = "Hello world It's a beautiful day" ...

  10. mysql索引命中规则

    转于:https://blog.csdn.net/claram/article/details/77574600 首先明确:为什么要用联合索引? 对于查询语句“SELECT E.* FROM E WH ...