poj2349 Arctic Network(最小生成树)
来源:互联网 发布:vscode md预览 编辑:程序博客网 时间:2024/05/16 15:37
Arctic Network
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 10718 Accepted: 3515
Description
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be 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 contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
12 40 1000 3000 600150 750
Sample Output
212.13/*题目大意:有s个站点,p个点,找要把所有点都连起来,但是这些点的连线都相同,要求连线最短思路:先找出最小生成树,把每段距离记录下来,因为有s个站点,所以有s个站点不需要连接,将距离从大到小排序,有s-1段是不需要的,只要找出来第s段就可以Time:2014-10-16 22:12*/#include<cstdio>#include<cstring>#include<algorithm>#include<climits>#include<cmath>using namespace std;#define MAX 510#define INF 10000*10010 struct Point{double x,y;}p[MAX];int N,M;double map[MAX][MAX],d[MAX];double minEdge[MAX];int k;bool cmp(double a,double b){return a>b;}double dis(Point a,Point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} void Prim(){double Mst;bool vis[MAX];memset(d,0,sizeof(d));memset(vis,0,sizeof(vis));for(int i=1;i<=M;i++){d[i]=map[1][i];//printf("%.2lf ",d[i]);}d[1]=0;vis[1]=true;for(int i=1;i<=M;i++){double minV=INF*1.0;int u=1;for(int j=1;j<=M;j++){if(!vis[j]&&minV>d[j]){minV=d[j];u=j;}}//printf("%lf\n",d[u]); if(minV==INF) return ;//Mst;//Mst+=d[u];minEdge[k++]=minV;vis[u]=true;for(int j=1;j<=M;j++){if(!vis[j]&&d[j]>map[u][j]){d[j]=map[u][j];}}}//return Mst;}void GetMap(){for(int i=1;i<=M;i++)for(int j=1;j<=M;j++)if(i!=j)map[i][j]=map[j][i]=dis(p[i],p[j]);else map[i][j]=0;}int main(){int T,S;scanf("%d",&T);while(T--){k=0;scanf("%d%d",&S,&M);N=(M*(M-1)>>1); for(int i=1;i<=M;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}GetMap();/*for(int i=1;i<=M;i++){for(int j=1;j<=M;j++)printf("%.2lf ",map[i][j]);printf("\n");}*/Prim();sort(minEdge,minEdge+k,cmp);//0---k S-1表示第S个 有S个站点,说明有S个不用连通 printf("%.2lf\n",minEdge[S-1]);}return 0;}
0 0
- poj2349 Arctic Network(最小生成树)
- poj2349 Arctic Network 最小生成树,kruskal
- POJ2349&ZOJ1914--Arctic Network【最小生成树】
- [poj2349 Arctic Network]最小生成树
- POJ2349 Arctic Network 最小生成树
- poj2349:Arctic Network(最小生成树)
- POJ2349 Arctic Network(最小生成树,Kruskal)
- poj2349 Arctic Network 最小生成树
- poj2349——Arctic Network(最小生成树+prim)
- POJ2349 Arctic Network 题解【最小生成树】【Kruskal】【图论】
- POJ2349(最小生成树)
- POJ2349 Arctic Network
- POJ2349--Arctic Network
- POJ2349---Arctic Network
- POJ2349,ZOJ1914,Arctic Network
- POJ2349 Arctic Network
- poj2349 Arctic Network
- POJ2349 Arctic Network
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--客户端对象模型和REST APIs概览 客户端对象模型API范围
- 数据结构与算法MOOC / 第2周 线性表(Linear Lists)1:约瑟夫问题
- [iOS高级] UICollectionView实现瀑布流效果
- JAVA九九乘法口诀
- Sicily 1151 魔板 Another Thought
- poj2349 Arctic Network(最小生成树)
- 20几岁,不要急着长大
- Linux Network Block Device(NBD)安装配置过程
- 查询执行完的JOB的消耗
- 插入排序,折半插入排序,希尔排序的代码
- 旅行-许巍
- Thread的run和start
- 使用C语言开发项目的一些心得
- mysql变量