题意:

给定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. 在MacOs上安装sqlsrv Mojave - 找不到'php.h'文件

    Mojave没有安装标头. 要安装标头: open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_1 ...

  2. kettle 导入xml 资源文件

    Repository | ExploreRight click the root node of the repositorySelect Import objects from an XML fil ...

  3. [CQOI2014]通配符匹配

    Description 几乎所有操作系统的命令行界面(CLI)中都支持文件名的通配符匹配以方便用户.最常见的通配符有两个,一个是星号(""'),可以匹配0个及以上的任意字符:另一个 ...

  4. cordova 安卓项目打包 release安装包

    问题描述: 打包安卓项目, 如果是在项目中只是使用debug包的话, 其中的签名方式使用的都是cordova框架本身, 那么每次打包的话, 都会把之前的安装包给覆盖掉. 现在打包做出一个release ...

  5. Apache下禁止使用IP直接访问本站的配置方法

    现在管的严啊,上面要求不能使用IP直接访问服务器,把apache配置做下调整就行了.方法如下: 打开apache的配置文件 # vi /usr/local/apache2/conf/extra/htt ...

  6. 【学习笔记】深入理解js原型和闭包(5)——instanceof

    又介绍一个老朋友——instanceof. 对于值类型,你可以通过typeof判断,string/number/boolean都很清楚,但是typeof在判断到引用类型的时候,返回值只有object/ ...

  7. pandas DataFrame 警告(SettingWithCopyWarning)

    转自:https://www.cnblogs.com/pig-fly/p/7875472.html 刚接触python不久,编程也是三脚猫,所以对常用的这几个工具还没有一个好的使用习惯,毕竟程序语言是 ...

  8. 如何查看安装的java是32位的,还是64位的

    命令 java -d32 -version 或者 java -d64 -version

  9. appium学习链接记录

    乙醇大师的园子: http://www.cnblogs.com/nbkhic/tag/appium/ webDriver java版 https://github.com/easonhan007/we ...

  10. 洛谷 P1021 邮票面值设计

    题目描述 给定一个信封,最多只允许粘贴N张邮票,计算在给定K(N+K≤15)种邮票的情况下(假定所有的邮票数量都足够),如何设计邮票的面值,能得到最大值MAX,使在1-MAX之间的每一个邮资值都能得到 ...