POJ2349 Arctic Network
原题链接
先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献。
显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除。
所以最后的答案就是最小生成树上第\(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的更多相关文章
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19113 Accepted: 6023 D ...
- POJ2349 Arctic Network(Prim)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16968 Accepted: 5412 D ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- POJ-2349 Arctic Network(最小生成树+减免路径)
http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- 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 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- for嵌套
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 解决iframe在iphone不兼容的问题
<div class="scroll-wrapper"> <iframe src="地址"></iframe> </d ...
- vue 语法糖
el:element 需要获取的元素,一定是HTML中的根容器元素data:用于数据的存储methods:用于存储各种方法数据绑定字面量只加载一次{{* msg}}data里面可以进行简单的运算:me ...
- svn git 必须理解的概念
不都是SCM代码管理嘛,有很大区别么?很多svn老鸟都是抱着这样的心态去学习git,然后无一幸免地陷入“查阅过很多资料,依然掌握不好”的困境,至少我们团队是这样的. 网上的资料确实已经很多了,却没有把 ...
- Real Time Rendering 1
[Real Time Rendering 1] 1.RTR是一本导论.官网:http://www.realtimerendering.com. 2.At around 6 fps, a sense o ...
- Physical (Raw) Versus Logical Backups
[Physical (Raw) Versus Logical Backups] Physical backups consist of raw copies of the directories an ...
- c# 项目的导入
1.打开 2.手动添加现有项目,对照后找到未添加的空间,然后打开底层 选择 “#”文件打开即可 3.每个空间分别添加隐藏项 注意 bin与obj不需要添加 4.添加引用 5.可能需要删除 li ...
- Avalon Framework
Apache Avalon has closed. Apache Avalon began in 1999 as the Java Apache Server Framework and in lat ...
- xnconvert 图片转换工具
xnconvert是一款简单高效的图片转换工具.xnconvert能够批量地进行图片格式转换,并具有一定的图片处理功能,可以增加水印.特效,支持放大缩小.旋转等. xnconvert功能介绍: 你可以 ...
- python--第五天总结
装饰器-- @ 重命名原函数,返回函数对象 是一个函数,至少两层执行函数,被装饰的函数作为参数----------------------------------------------------1 ...