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]);
    	}
    }


  • 相关阅读:
    猴子选大王(约瑟夫环)
    centos 安装thrift
    KMP字符串匹配算法
    会话技术整理
    PHP数组整理版
    PHP基础知识6【系统内置函数--数组】
    PHP基础知识5【系统内置函数--字符串】
    PHP基础知识笔记4
    PHP基础知识笔记3
    PHP基础知识笔记2
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273836.html
Copyright © 2011-2022 走看看