原题链接

先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献。

显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除。

所以最后的答案就是最小生成树上第\(m\)长的边。

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N = 510;
struct cod {
int x, y;
};
cod a[N];
int n;
double eg[N][N], dis[N];
bool v[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline double minn(double x, double y)
{
return x < y ? x : y;
}
void prim()
{
int i, j, x;
memset(dis, 65, sizeof(dis));
memset(v, 0, sizeof(v));
dis[1] = 0;
for (i = 1; i <= n; i++)
{
x = 0;
for (j = 1; j <= n; j++)
if (!v[j] && (!x || dis[j] < dis[x]))
x = j;
if (!x)
break;
v[x] = 1;
for (j = 1; j <= n; j++)
if (!v[j])
dis[j] = minn(dis[j], eg[x][j]);
}
}
int main()
{
int i, j, m, t;
t = re();
while (t--)
{
m = re();
n = re();
for (i = 1; i <= n; i++)
{
a[i].x = re();
a[i].y = re();
}
for (i = 1; i < n; i++)
for (j = i + 1; j <= n; j++)
eg[j][i] = eg[i][j] = sqrt(1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x) + 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y));
prim();
sort(dis + 1, dis + n + 1);
printf("%.2f\n", dis[n - m + 1]);
}
return 0;
}

POJ2349 Arctic Network的更多相关文章

  1. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

  2. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  3. POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19113   Accepted: 6023 D ...

  4. POJ2349 Arctic Network(Prim)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16968   Accepted: 5412 D ...

  5. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

  6. POJ-2349 Arctic Network(最小生成树+减免路径)

    http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...

  7. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  8. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

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

  9. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. tensorflow serving 之minist_saved_model.py解读

    最近在学习tensorflow serving,但是就这样平淡看代码可能觉得不能真正思考,就想着写个文章看看,自己写给自己的,就像自己对着镜子演讲一样,写个文章也像自己给自己讲课,这样思考的比较深,学 ...

  2. windows 下 redis安装

    在D盘新建文件夹[redis],右键解压Redis ZIP包,把所有文件解压到redis文件夹中.(其他盘符也可以滴^_^) 文件介绍: redis-benchmark.exe         #基准 ...

  3. 2018面向对象程序设计(Java)第8周学习指导及要求

    2018面向对象程序设计(Java)第8周学习指导及要求 (2018.10.18-2018.10.21)   学习目标 掌握接口定义方法: 掌握实现接口类的定义要求: 掌握实现了接口类的使用要求: 理 ...

  4. 提升系统的QPS和吞吐量

    简单而言通过增加集群来提升qps和吞吐量 实际上要比这个要复杂 首先我们需要知道系统的瓶颈 我们所知道的系统拓扑架构 对于rest接口而言 系统设施依次是: dns nginx tomcat db/s ...

  5. response.sendfile() fails with Error: Forbidden

    [response.sendfile() fails with Error: Forbidden] 参考:https://github.com/expressjs/express/issues/146 ...

  6. centos最小安装之后无法使用ifconfig

    Centos7安装之后,无法使用ifconfig(找不到命令) 运行 yum install provides 再安装net-tools即可 yum install net-tools 没有网,下载r ...

  7. SSL、TLS中间人攻击

    生成私钥 生成一个ca.key私钥签名 然后用私钥生成一个伪造证书服务器的根证书 生成一个伪造证书服务器的根证书ca.crt 在攻击主机启动路由转发功能 或者echo 1 > /proc/sys ...

  8. openjdk1.8 源码地址

    http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/656ab3b39178/src/

  9. linux之master和minion

    saltstack博客地址: https://www.cnblogs.com/pyyu/p/9465608.html在线yaml文件编写:http://www.bejson.com/validator ...

  10. 贪吃蛇Listener Java实现(二)

    package cn.tcc.snake.listener; import cn.tcc.snake.antition.Sanke;//接口//处理用户按键事件public interface Sna ...