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 ...
随机推荐
- 历届试题 小数第n位-(同余公式+快速幂)
问题描述 我们知道,整数做除法时,有时得到有限小数,有时得到无限循环小数. 如果我们把有限小数的末尾加上无限多个0,它们就有了统一的形式. 本题的任务是:在上面的约定下,求整数除法小数点后的第n位开始 ...
- js基础-基本包装类型
var t = 13; t.toString(); //t是一个简单数值类型 现在有了方法 toString 对象类型的方法 //数值类型有对应的包装类型 var t1 =new Number(333 ...
- 通过网址request到response经历的过程
前言当我们在浏览器中输入一个网址,比如www.google.cn,浏览器就会加载出百度的主页.那么浏览器背后完成的具体是怎么样的呢? 总结起来大概的流程是这样的: (1)浏览器本身是一个客户端,当你输 ...
- Java中的冒泡排序和选择排序
//冒泡排序 public class Test5 { public static void main(String[] args) { int[] arr = {12,2,25,89,5}; bub ...
- spring读取工程外配置文件
因为生产和开发测试的环境不同,所以有时候需要把properties文件放在包外方便修改配置. spring配置文件如下: <context:property-placeholder locati ...
- Appium1.6 GUI界面介绍
Appium1.6安装详见随笔:http://www.cnblogs.com/meitian/p/7360017.html 下面具体介绍一下GUI界面 1.appium server配置页面 2. ...
- spark快速开发之scala基础之2控制流程
判断结构 大体与java相当.scala没有三元表达式. val num = if(1>0) 1 else 0 //相当于匿名函数 println(num) var num2 = 0 if(1& ...
- FileInputStream.FileOutputStream执行图片复制
/** * 需求:拷贝一个图片 * 思路: * 1.创建一个字符输入流和图片相关联. * 2.用字节写入流对创建图片文件,用于存储到图片数据. * 3.通过循环续写,完成数据的存储. * 4.关闭资源 ...
- poj1019(打表预处理+数学)
题目链接:http://poj.org/problem?id=1019 题意:对于序列1121231234...,求第i个数字(i<=2147483647). 思路:记第一组为1,第二组为12, ...
- 解决镜像无法删除的问题multiple repositories
Error response from daemon: conflict: unable to delete ea5f89e79b1e (must be forced) - image is refe ...