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++的区别

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

最新文章

  1. MVC Controller Dependency Injection for Beginners【翻译】
  2. 剑指Offer 整数中1出现的次数(从1到n整数中1出现的次数)
  3. java 多线程—— 线程等待与唤醒
  4. C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习
  5. 深入浅出MongoDB(一)NoSQL
  6. BZOJ 2456
  7. .NET平台技术体系梳理+初学者学习路径推荐+我们的愿景与目标
  8. 炼数成金hadoop视频干货02
  9. jquery 下拉框 收藏
  10. 使用SevenZipSharp出现“Can not load 7-zip library or internal COM error! Message: DLL file does not exist.”的解决方案
  11. C++继承(07)
  12. Mysql SQL分组取每组前几条记录
  13. nc 使用实例
  14. mimikaz常用命令
  15. 关于Laravel 迁移数据库的问题
  16. Eclipse 在Debug调试中用到的快捷键
  17. Echart 仪表盘和柱形图
  18. Java文件复制删除操作合集
  19. MySQL-关于并发下的mysql_insert_id()
  20. .NET正则表达式Regex

热门文章

  1. 12)Java Constructor
  2. lua进阶(一)
  3. 【标题】一本帮你提高Excel办公效率的VBA书
  4. 3.html5的文本元素
  5. java 中 java.lang.ArrayIndexOutOfBoundsException: 0 异常
  6. WPF工作笔记:本地化支持、主进程通知、两种最常用异步编程方式
  7. 刀哥多线程之一次性代码gcd-11-once
  8. 从零开始学ios开发(四):IOS控件(1),Image View、Text Field、Keyboard
  9. mysql字段累加concat
  10. MVC4.0 WebApi如何自定义返回数据类型