POJ-2349-Arctic Network
来源:互联网 发布:传奇世界db数据库参数 编辑:程序博客网 时间:2024/05/22 14:50
题意:给你S个卫星和P个哨兵,哨兵之间的沟通有两种方式,一种是通过卫星无论多大的距离都能,另一种是无线这种就要考虑距离,距离越大代价也就越大,但是哨兵必须要用一样的,让你求出用多大代价的无线设备才能使所有的哨兵之间有联系的代价最小,并输出那个代价最小要用的那个无线设备的代价。
思路:刚开始把这个题想的很复杂,后来一想就是先找一个最小生成树,完了再去掉最大S-1条线,剩下的最大的代价就是所求了。
AC代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;const int maxn=510;const int maxm=maxn*maxn/2;int T,n,m,k;double edge[maxn];struct Node{ int x; int y;} d[maxn];struct node{ int l; int r; double w;} t[maxm];int p[maxn];int Find(int x){ if(p[x]==-1) return x; return p[x]=Find(p[x]);}int cmp(struct node a,struct node b){ return a.w<b.w;}double lpf(){ int cnt=0; for(int i=0; i<k; i++) { int a=Find(t[i].l); int b=Find(t[i].r); if(a!=b) { edge[cnt++]=t[i].w; p[a]=b; } } return edge[cnt-n]; //除去最大的S-1条边最大的边}int main(){ scanf("%d",&T); while(T--) { memset(p,-1,sizeof(p)); scanf("%d%d",&n,&m); k=m*(m-1)/2; for(int i=0; i<m; i++) scanf("%d%d",&d[i].x,&d[i].y); int cnt=0; for(int i=0; i<m; i++) { for(int j=i+1; j<m; j++) { t[cnt].l=i; t[cnt].r=j; t[cnt++].w=sqrt((d[i].x-d[j].x)*(d[i].x-d[j].x)*1.0+(d[i].y-d[j].y)*(d[i].y-d[j].y)*1.0); } } sort(t,t+cnt,cmp); printf("%.2lf\n",lpf()); } return 0;}
0 0
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- poj 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- POJ-2349-Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- Poj 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349-Arctic Network
- poj 2349 Arctic Network
- java Future 接口介绍
- jQuery Mobile动态刷新页面样式
- 怎样通过iPhone Safari 来安装测试版ipa
- Android中的长度单位详解
- AFNetworking2安全的使用自签证书访问
- POJ-2349-Arctic Network
- 连连看小游戏,递归问题
- .javaweb:hover
- armv6, armv7, armv7s的区别
- VC++定制状态栏
- 摘自《张亚勤——让智慧起舞》
- 分治算法求最近点对
- 17.JavaWeb基础 Ajax(局部刷新)
- linux下查询/关闭/启动svn进程