zoukankan      html  css  js  c++  java
  • Arctic Network

                                                     Arctic Network

    Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
    Total Submission(s) : 6   Accepted Submission(s) : 3
    Problem 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.
     

    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
    1 2 4 0 100 0 300 0 600 150 750
     

    Sample Output
    212.13
     

    题意:第一个数字表示数据的组数,每组测试数据第一行,第二个数字表示点的个数,连成最小生成树之后,第一个数字就表示第多少长的边,裸地prim,需要记录每次挑选出来的min,然后排序,代码如下




    #include<stdio.h>
    #include<string.h>
    #define INF 0xfffffff
    #include<math.h>
    #include<stdlib.h>
    #include<algorithm>
    using namespace std;
    int cmp(double a,double b)
    {
    	if(a>b)
    	return 1;
    	return 0;
    }
    double x[1010],y[1010],map[1010][1010],ans[1010];
    int v[1010];
    double dis(double x1,double y1,double x2,double y2)
    {
    	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    int main()
    {
    	int t;
    	scanf("%d",&t);
    	while(t--)
    	{
    		int s,p,i,j,flag,cot=0;
    		double min;
    		scanf("%d%d",&s,&p);
    		for(i=1;i<=p;i++)
    		{
    			for(j=1;j<=p;j++)
    			{
    				map[i][j]=INF;
    			}
    		}
    		for(i=1;i<=p;i++)
    		{
    			scanf("%lf%lf",&x[i],&y[i]);
    			for(j=1;j<i;j++)
    			{
    				map[i][j]=map[j][i]=dis(x[i],y[i],x[j],y[j]);
    			}
    		}
    		memset(v,0,sizeof(v));
    		v[1]=1;
    		for(i=1;i<=p;i++)
    		{
    			flag=-1;
    			min=INF;
    			for(j=1;j<=p;j++)
    			{
    				if(!v[j]&&map[1][j]<min)
    				{
    					min=map[1][j];
    					flag=j;
    				}
    			}
    			if(flag==-1)
    				break;
    			v[flag]=1;
    			ans[cot++]=min;
    			for(j=1;j<=p;j++)
    			{
    				if(!v[j]&&map[1][j]>map[flag][j])
    					map[1][j]=map[flag][j];
    			}
    		}
    		sort(ans,ans+cot,cmp);
    		printf("%.2lf
    ",ans[p-s-1]);
    	}
    }


  • 相关阅读:
    2-Fourteenth Scrum Meeting-20151214
    2-Thirteenth Scrum Meeting-10151213
    2-Twelfth Scrum Meeting20151212
    2-Eleventh Scrum Meeting20151211
    L465 Climate Change May Take Away Your Ability to Flush the Toilet
    L458 Interview
    L457 早上锻炼减肥
    L456 学英语 看美剧
    L455 人之初,性本衰
    L454 正确喝水
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273836.html
Copyright © 2011-2022 走看看