poj2349Arctic Network (最小生成树运用)
来源:互联网 发布:redis 持久化数据库 编辑:程序博客网 时间:2024/06/05 01:00
现在有s个卫星设备可以安装,还有足够多的无线电设备,求一个方案,使得费用D最少(D取决与所有用无线电通信的花费最大的那条路径)。
思路:一看前面的使得任意两个科研站直接或者间接相连就想到最小生成树,那么因为D越长费用越多,基于贪心的思想,所以肯定是把最小生成树前s-1条最长的边用卫星连接(S个卫星最多可以连接S-1条边),将最小生成树每一条边的权值保存下来,假设有n个科研站的话那么就有n-1条边相连,把前s-1条边用卫星连接之后,那么剩下的最大的就是d[n-s-1]
#include<cstring>#include<string>#include<fstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cctype>#include<algorithm>#include<queue>#include<map>#include<set>#include<vector>#include<stack>#include<ctime>#include<cstdlib>#include<functional>#include<cmath>using namespace std;#define MAXN 1000010#define INF 0x7FFFFFFF#define ll long longstruct node{ int u,v; double dis;}edge[MAXN];int father[550];int n,m,cnt,s;double x[550],y[550];double ans[550];bool cmp(node x,node y){ return x.dis<y.dis;}int find(int x){ int t = x; while(father[t]!=t){ t = father[t]; } int k = x; while(k!=t){ int temp = father[k]; father[k] = t; k = temp; } return t;}void kruskal(){ int i,j=0; for(i=1;i<=n;i++) father[i] = i; for(i=0;i<m;i++){ int a = find(edge[i].u); int b = find(edge[i].v); if(a!=b){ father[a] = b; ans[cnt++] = edge[i].dis; j++; if(j>=n-1) break; } }}int main(){ int t,i,j,a,b; scanf("%d",&t); while(t--){ cnt = 0; m = 0; scanf("%d%d",&s,&n); for(i=1;i<=n;i++){ scanf("%lf%lf",&x[i],&y[i]); for(j=1;j<i;j++){ edge[m].u = i; edge[m].v = j; double temp = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]); edge[m].dis = sqrt(temp); m++; } } sort(edge,edge+m,cmp); kruskal(); printf("%.2f\n",ans[n-s-1]); } return 0;}
The Department of NationalDefence (DND) wishes toconnect several northern outpostsby a wireless network.Two different communicationtechnologies are to beused in establishing the network:every outpost willhave a radio transceiver andsome outposts will in additionhave a satellite channel.Any two outposts witha satellite channel can communicatevia the satellite,regardless of their location.Otherwise, two outposts cancommunicate by radio onlyif the distance between themdoes not exceed D, which dependsof the power of thetransceivers. Higher poweryields higher D but costsmore. Due to purchasingand maintenance considerations,the transceivers at theoutposts must be identical;that is, the value of D is thesame for every pair of outposts.Your job is to determinethe minimum D required forthe transceivers. There mustbe at least one communication path (direct or indirect) between every pair of outposts.
Input
The first line of input contains N, the number of test cases. The first line of each test case contains1 ≤ S ≤ 100, the number of satellite channels, and S < P ≤ 500, the number of outposts. P linesfollow, giving the (x, y) coordinates of each outpost in km (coordinates are integers between 0 and10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect thenetwork. Output should be specified to 2 decimal points.
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
- poj2349Arctic Network (最小生成树运用)
- poj2349Arctic Network最小生成树
- POJ2349Arctic Network(最小生成树)
- POJ2349Arctic Network之最小生成树kruskal解法
- poj2349Arctic Network(最小生成树kruscal+第k长的边)
- poj 1861Network(最小生成树)
- E - Network(最小生成树)
- poj 1861 Network(最小生成树)
- poj2349 Arctic Network(最小生成树)
- POJ Network(最小生成树--kruskul)
- zoj1586 QS Network(最小生成树)
- ZOJ QS Network(最小生成树)
- QS Network(最小生成树)
- poj1861--Network(最小生成树)
- POJ_2349_Arctic Network(最小生成树)
- POJ1861 Network(最小生成树)
- zoj 1542 Network(最小生成树))
- zoj 1586 QS Network(最小生成树))
- PHP 关于json_decode返回数组还是对象。
- PorterDuffXferMode使用注意点
- iOS-点击按钮实现复制功能
- c#中DataTime类型的常用操作整理
- 各式各样的正则表达式参考大全
- poj2349Arctic Network (最小生成树运用)
- Block两种定义
- 从IA32到X86-64的扩展所导致的函数传参栈模型的变化
- 月季年TOP 模型-月
- 使用addChildViewController 遇到没有加载的controller viewdidload也被调用
- android项目中出现的错误
- AndroidStudio中使用开源框架android-gif-drawable
- Canvas模仿微信红包照片
- Windows winsock2 SPI使用