原题链接

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

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

所以最后的答案就是最小生成树上第\(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. java第一课总结

    转眼间开学了,我们也正式进入了大二.心里既有激动,又有些感慨,还带有一些担忧.激动的是我们褪去了大一的稚气成为了一名大二的学长了,第一次体会到了大学学长的感觉,心里很是激动.感慨的是我们又成长了一岁, ...

  2. html5新增标签做基本布局

    结构标记 ***** 做布局 1.<header>元素 <header></header> ==> <div id="header" ...

  3. JMeter学习(十一)WebSerivice测试计划(转载)

    转载自 http://www.cnblogs.com/yangxia-test WebSerivice测试计划的取样器有两种方式:HTTP请求.SOAP/XML-RPC Request. 1. 测试计 ...

  4. Swagger2

    参考文档:https://www.jianshu.com/p/5ae7267385b9 官网:https://swagger.io/ 注解参考:https://blog.csdn.net/weixin ...

  5. python学习day6 for循环 字符串的内置方法

    1.for循环 和while相比 l=[1,2,3] i=0 while i <len(l) print(l[i]) i+=1 l=['a','b','c'] for item in l: pr ...

  6. tab template

    <div class="box"> <div class="box-body"> <div class="nav-tab ...

  7. java并发:CopyOnWriteArrayList简单理解

    Java集合的快速失败机制 “fail-fast” "fail-fast"是java集合的一种错误检测机制,当多个线程对集合进行结构上的改变的操作时,有可能会产生 fail-fas ...

  8. Idea单元测试Junit Generator设置

    0. setting--->plugins--->brose repostories-->输入JUnitGenerator V2.0 1.junit generator自动生成测试代 ...

  9. codeblocks17.12 不能启动调试器

    调试器需要手动指定. settings->debugger->default->executable path.这里默认空的,需要指定.路径在安装目录下的CodeBlocks\Min ...

  10. Cron 表达式

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: (1) Seconds Minutes Hours DayofMonth Mo ...