LOJ P10065 北极通讯网络 题解
每日一题 day39 打卡
Analysis
1.当正向思考受阻时,逆向思维可能有奇效。
2.问题转化为:找到最小的d,使去掉所有权值>d的边之后,连通支的个数<k;
3.定理:如果去掉所有权值>d的边之后,最小生成树被分割为k个连通支,则图也被分为k个连通支。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 10000000+10
#define INF 9187201950435737471
#define rep(i,s,e) for(register int i=s;i<=e;++i)
#define dwn(i,s,e) for(register int i=s;i>=e;--i)
using namespace std;
inline int read()
{
int x=;
bool f=;
char c=getchar();
for(; !isdigit(c); c=getchar()) if(c=='-') f=;
for(; isdigit(c); c=getchar()) x=(x<<)+(x<<)+c-'';
if(f) return x;
return -x;
}
inline void write(int x)
{
if(x<){putchar('-');x=-x;}
if(x>)write(x/);
putchar(x%+'');
}
int n,k,cnt,tot;
int f[maxn];
double ans[maxn];
struct node1
{
int x,y;
}coo[maxn];
struct node2
{
int xx,yy;
double dis;
}tree[maxn];
inline double calc(int x_,int y_,int x__,int y__)
{
return sqrt(((double)x_-(double)x__)*((double)x_-(double)x__)+((double)y_-(double)y__)*((double)y_-(double)y__));
}
inline int find(int x)
{
if(f[x]==x) return x;
return f[x]=find(f[x]);
}
bool cmp(node2 x,node2 y)
{
return x.dis<y.dis;
}
signed main()
{
rep(i,,) f[i]=i;
n=read();k=read();
rep(i,,n) coo[i].x=read(),coo[i].y=read();
rep(i,,n)
rep(j,i+,n)
{
tree[++cnt].xx=i;
tree[cnt].yy=j;
tree[cnt].dis=calc(coo[i].x,coo[i].y,coo[j].x,coo[j].y);
}
sort(tree+,tree+cnt+,cmp);
rep(i,,cnt)
{
int f1=find(tree[i].xx);
int f2=find(tree[i].yy);
if(f1!=f2)
{
f[f1]=f2;
ans[++tot]=tree[i].dis;
if(tot==n-) break;
}
}
printf("%.2lf",ans[tot-k+]);
return ;
}
请各位大佬斧正(反正我不认识斧正是什么意思)
LOJ P10065 北极通讯网络 题解的更多相关文章
- LOJ#10065. 「一本通 3.1 例 2」北极通讯网络
题目链接:https://loj.ac/problem/10065 题目描述 原题来自:Waterloo University 2002 北极的某区域共有 nnn 座村庄,每座村庄的坐标用一对整数 ( ...
- Arctic Network(洛谷)--北极通讯网络(loj)
洛谷传送门 loj传送门 一道蛮基础的最小生成树的题 题意也没绕什么圈子 只是叙述的有点累赘而已(loj上是这样的 也就读入加建边需要稍稍稍多想一下下 对于我这么一个蒟蒻 这是一道很好的板子题 (洛谷 ...
- [暑假集训Day1T2]北极通讯网络
这题主要考察对“卫星电话”的理解,k个卫星电话相当于可以让k个联通块保持联通,因此我们只需要让原图连成k个联通块,然后给每个联通块的任意一个节点发一部卫星电话即可.因此我们需要连n-k条边,特别地,当 ...
- C/C++ 用libcurl库进行http通讯网络编程
C/C++ 用libcurl库进行http通讯网络编程 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_p ...
- C++ 用libcurl库进行http通讯网络编程 【转】
http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html C++ 用libcurl库进行http通讯网络编程 目录索引: 一.Lib ...
- C++ 用libcurl库进行http通讯网络编程
使用libcurl完成http通讯,很方便而且是线程安全,转载一篇比较好的入门文章 转载自 http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724 ...
- Java Socket通讯---网络基础
java socket 通讯 参考慕课网:http://www.imooc.com/learn/161 一.网络基础知识 1.1 通讯示意图 1.2 TCP/IP协议 TCP/IP是世界上应用最为广泛 ...
- C++ 用libcurl库进行http通讯网络编程(转)
转载:http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三. ...
- C++ 用libcurl库进行http通讯网络编程[转]
http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.cur ...
随机推荐
- Linux 总结篇
1. sudo -i update upgrade install 包名 (openjdk-8-jdk) autoremove 自动删除不需要的包(remove卸载) sudo apt-get 2. ...
- go条件变量的使用和原理
场景 最近写代码时碰到一个场景, 需要使用 map[int]struct{} 结构来存储task, map的key是task的id,随时可以增减.因为的确除了看书,基本上没使用过条件变量所以后面过了一 ...
- L2R 一:基础知识介绍
一.背景 l2r可以说是搜索推荐里面很常用的知识了,一直处于一知半解的地步,今天开个博客准备把这些零散的东西系统性整理好,一版就粗糙点了. 二.粗概 前段时间的项目主要和搜索引擎相关,记录下搜索引擎的 ...
- (转)nginx与PHP的关系
php是一门编程语言,可以编写很多程序,但是只有php的话,你的php只能在你的服务器里孤立的运行,比如你用php写了一个可以通过身高计算人的标准体重的程序,虽然这个程序可以在服务器运行,但是他还不能 ...
- 单例DCL模式
单例模式可以保证系统中一个类只有一个实例.即一个类只有一个对象实例. 一般写法 public class DCLSingle { public static DCLSingle instance= n ...
- resnet的理解-- 面试笔记
上周参加了XX大学研究生推免的面试,面试老爷问到了resnet主要解决了什么问题,我下意识的回答到解决了当网络加深的时候会出现的vanishing/exploding gradients,然后面试老爷 ...
- Django使用LDAP
https://github.com/python-ldap/python-ldap Quick usage example: import ldap l = ldap.initialize(&quo ...
- JS权威指南读书笔记(七)
第十七章 事件处理 1 客户端JS程序采用了异步事件驱动编程模型. 2 关于事件的重要定义 a 事件类型(event type) b 事件目标(event target) target ...
- ERROR: Cannot uninstall 'chardet'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
pip 安装 docker库报错: ERROR: Cannot uninstall 'chardet'. It is a distutils installed project and thus we ...
- Chrome谷歌浏览器插件-小结
1.小插件库: Tampermonkey https://chrome.google.com/webstore/detail/tampermonkey-beta/gcalenpjmijncebpfij ...