Arctic Network
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9557   Accepted: 3187

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

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<stack>
using namespace std;
double map[505][505];
int dx[505][2];
double ad[255005];
int n, m; double cl(int x, int y,int k , int l )
{
double a = x;
double b = y;
double c = k;
double d = l;
return sqrt((a-c)*(a-c)+(b-d)*(b-d));
} int prim()
{
int i, j, k, s = 0;
double dis[505]={0};
int vis[505]={0};
dis[0] = 200000;
vis[1] = 1;
for(i=1;i<=m;i++) dis[i]=map[1][i];
for(i=1;i<m;i++)
{
k = 0;
for(j=1;j<=m;j++)
{
if(dis[j]<dis[k] && vis[j]==0 && dis[j]) k = j;
}
vis[k] = 1;
ad[s++]=dis[k];
for(j=1;j<=m;j++)
{
if(vis[j]) continue;
if((dis[j]>map[k][j] || dis[j]==0 ) && map[k][j] ) dis[j]=map[k][j];
}
}
return s;
} int main()
{
int a, b, c, key;
// freopen("in.txt","r+",stdin);/*如果in.txt不在连接后的exe的目录,需要指定路径如D:\\in.txt*/
// freopen("out.txt","w+",stdout);/*同上*/
scanf("%d",&key);
while(key--)
{
memset(map,0,sizeof(map));
memset(map,0,sizeof(dx));
memset(map,0,sizeof(ad));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
dx[i][0] = a;
dx[i][1] = b;
} for(int i=1;i<=m;i++)
{
for(int j=i;j<=m;j++)
{
map[i][j] = map[j][i] = cl(dx[i][0],dx[i][1],dx[j][0],dx[j][1]);
}
} // for(int i=1;i<=m;i++)
// {
// for(int j=1;j<=m;j++) printf("%lf ",map[i][j]);
// printf("\n");
// } prim();
sort(ad,ad+m-1);
printf("%.2lf\n",ad[m-n-1]);
}
// fclose(stdin);
// fclose(stdout); return 0;
}

请选择C++编译器,不要选择G++,这就是为什么你WA的主要原因

论G++与C++的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。

Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏的更多相关文章

  1. Poj 1050 分类: Translation Mode 2014-04-04 09:31 103人阅读 评论(0) 收藏

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39058   Accepted: 20629 Desc ...

  2. 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏

    第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...

  3. *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏

    *** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...

  4. sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏

    sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...

  5. Poj 2528 Mayor's posters 分类: Brush Mode 2014-07-23 09:12 84人阅读 评论(0) 收藏

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40570   Accepted: 11798 ...

  6. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏

    PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...

  8. 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏

    4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...

  9. 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏

    Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...

随机推荐

  1. WordPress默认栏目设置

    WordPress是一个注重美学.易用性和网络标准的个人信息发布平台,是全球使用最多的博客系统,只需要在系统后台做一些简单的设计,基本就能实现我们日常个性化发布个人信息的需求,而博客后台的使用其实很简 ...

  2. Android四大组件一----Activity

    最新面试需要复习一下Android基础. {所谓Activity} 通俗点:app上看到的窗口基本都是Activity Android 程序一般是由多个Activity组成,用户看到的能够交互的窗口通 ...

  3. Flask Web Development —— Web表单(上)

    Flask-WTF扩展使得处理web表单能获得更愉快的体验.该扩展是一个封装了与框架无关的WTForms包的Flask集成. Flask-WTF和它的依赖集可以通过pip来安装: (venv) $ p ...

  4. jquery.unobtrusive-ajax.js源码阅读

    /*! ** Unobtrusive Ajax support library for jQuery ** Copyright (C) Microsoft Corporation. All right ...

  5. Node.js学习笔记 01 搭建静态服务器

    希望这篇文章能解决你这样一个问题:“我现在已经了解了一些Node.Js基本概念了,怎么搭一台静态服务器呢?” 请参考一下博主的前两篇文章: 完全面向于初学者的Node.js指南 Node.Js的Mod ...

  6. Microsoft Power BI Designer

    1/25/2015年1月25发布的预览版本,可以通过以下地址下载,注意有x64 和x32 版本区别(和上次PowerMap一样,一般也推荐的使用x64版本) http://www.microsoft. ...

  7. 菜鸟学习Spring——60s让你学会动态代理原理

    一.为什么要使用动态代理         当一个对象或多个对象实现了N中方法的时候,由于业务需求需要把这个对象和多个对象的N个方法加入一个共同的方法,比如把所有对象的所有方法加入事务这个时候有三种方法 ...

  8. strcpy/strlen/strcat/strcmp面试总结

    <strcpy拷贝越界问题> 一. 程序一 #include<stdio.h> #include<string.h> void main() { char s[]= ...

  9. c++基础(三):多态

    virtual:虚函数.C++通过虚函数实现多态."无论发送消息的对象属于什么类,它们均发送具有同一形式的消息,对消息的处理方式可能随接手消息的对象而变"的处理方式被称为多态性.& ...

  10. ios 唯一标示符

    大家知道苹果每部 iOS 设备都有一个 UDID,它就像设备的身份证一样,记录着设备的名称.类型甚至一些关于用户的私人信息.通常情况下,UDID 的一个最大功能就是帮助广告发布商向特定用户推送定向广告 ...