野人部落
来源:互联网 发布:jeeplus 工作流源码 编辑:程序博客网 时间:2024/05/17 03:03
裸的K算法,枚举最小边,当两个点不在一个连通块的时候,就可以减少连通块的数量,然后直到有k个联通块时,输出下一个合法的边
#include <cstdio>#include <iostream>#include <cmath> #include <algorithm>using namespace std;double x[1010],y[1010];struct tw{ int p1; int p2; double dis;};tw d[1000*1000+100];int cnt;int fat[1010];bool comp(const tw&a,const tw&b){ return a.dis<b.dis;}int find(int x){ if(x==fat[x]) return x; return fat[x]=find(fat[x]);}int main(){ int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) fat[i]=i; for(int i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) d[++cnt].dis=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])),d[cnt].p1=i,d[cnt].p2=j; sort(d+1,d+cnt+1,comp); int kis=n; int now=1; while(1) { if(kis==k) break; int fx=find(d[now].p1); int fy=find(d[now].p2); if(fx!=fy) fat[fx]=fy,kis--; now++; } while(1) { int fx=find(d[now].p1); int fy=find(d[now].p2); if(fx!=fy) { printf("%.2lf",d[now].dis); break; } now++; } return 0;}
阅读全文
0 0
- 野人部落
- 荒岛野人
- 荒岛野人
- 博客部落
- 存储部落
- 部落意愿
- 地精部落
- 部落卫队
- 部落冲突
- 部落卫队
- 作业部落
- 部落冲突
- 野人花园 savage guarden
- 修道士与野人问题
- 野人与传教士
- 传教士野人过河问题
- 野人传教士问题
- 野人过河问题
- XMLHttpRequest对象属性及常用方法
- 程序优化
- mysql给表的字段加索引
- 使用软引用构建敏感数据的缓存
- tomcat的发布
- 野人部落
- NAN论文解读:Neural Aggregation Network for Video Face Recognition
- 屏幕的一些数据
- redis-入门篇
- 初学acmer--读《算法竞赛入门经典》笔记(二) p25-27
- 阿里云首推音乐变速短视频SDK,上线抖音 freestyle只需1步
- MySQL数据库性能优化之存储引擎选择
- 虚拟化 cpu的ring0 ring1又是什么概念?
- Spring Cloud学习 -- 配置管理