首页 技术 正文
技术 2022年11月15日
0 收藏 705 点赞 3,344 浏览 1303 个字

题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高。

输入的数据意思:

实例个数

卫星个数   站点个数

每个站点的坐标

输出的意思:

发射器最小是多少,保留两位小数

注意事项:

其中卫星数量少于站点,存边的数组下标从0开始的,还有一个坑坑,输出用的.2f,而喜欢用.2lf的我错了四发才发现….

代码如下:

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue> using namespace std; const int N = ;
double INF = 0x3f3f3f3f3f3f;
double cost[N][N],used[N];
bool visit[N];
double lowc[N];
int c;
bool cmp(double a,double b)
{
return a>b;
}
void Prim(int n)
{
memset(visit,false,sizeof(visit));
visit[] = true;
for(int i = ; i < n; i++) lowc[i] = cost[][i];
for(int i = ; i < n; i++)
{
double minc = 1.0*INF;
int p = -;
for(int j = ; j < n; j++)
{
if(!visit[j] && minc - lowc[j] > 1e-)
{
minc = lowc[j];
p = j;
}
}
visit[p] = true;
used[c++]= minc;
for(int j = ; j < n; j++)
{
if(!visit[j] && lowc[j] - cost[p][j] > 1e-)
lowc[j] = cost[p][j];
}
}
}
struct nodes
{
double x,y;
}point[N]; int main(void)
{
int i,j,t,m,n;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
for(i = ; i < n; i++)
scanf("%lf %lf",&point[i].x,&point[i].y);
for(i = ; i < n; i++)
for(j = ; j < n; j++)
cost[i][j] = cost[j][i] = INF; for(i = ; i < n; i++)
for(j = i + ; j <n; j++)
{
double temp = sqrt( (point[i].x-point[j].x)*(point[i].x-point[j].x) +(point[i].y-point[j].y)*(point[i].y-point[j].y));
cost[i][j] = cost[j][i] = temp;
}
memset(used,,sizeof(used));
c = ;
Prim(n);
sort(used,used+c,cmp);
printf("%.2f\n",used[m-]);//.2f神坑
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905