bzoj 1821: [JSOI2010]Group 部落划分 Group(并查集)
来源:互联网 发布:sqlserver触发器 编辑:程序博客网 时间:2024/06/08 17:05
点击打开链接
中文题意开心
思路:把题面上的问题抽象一下就能得到就是,在部落里的人的距离都是0,部落的距离定义为两个部落中距离最近的点的距离,那他让最近的部落的距离最远,那我们初始使让每一个人都是一个部落,然后按距离排序,距离近的我们让他们在一个部落里,直到划分成为k个部落的时候就停止,那么这个距离就是我们要的距离
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;const int maxn = 1100;struct node{ int x,y; float v;}edg[maxn*maxn];int x[1100],y[1100];int p[maxn*maxn];int getf(int x){ return x == p[x] ? x: p[x] = getf(p[x]);}bool cmp(node a,node b){ return a.v<b.v;}int main(){ int n,m; scanf("%d%d",&n,&m); for(int i = 0 ; i < n ; i++) { scanf("%d%d",&x[i],&y[i]); } int cnt = 0 ; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j <i ; j++) { edg[cnt].v = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); edg[cnt].x = i; edg[cnt++].y = j; } } for(int i = 0 ; i < cnt ; i ++) { p[i] = i;} int Cnt = n-1; int ans = 0; sort(edg,edg+cnt,cmp); for(int i = 0 ; i < cnt ;i++) { int dx = getf(edg[i].x); int dy = getf(edg[i].y); //cout<<cnt<<endl; if(dx!=dy) { p[dx] = dy; Cnt --; } if(Cnt<m-1) { ans = i; break; } } printf("%.2f\n",edg[ans].v);}
阅读全文
0 0
- bzoj 1821: [JSOI2010]Group 部落划分 Group(并查集)
- 1821: [JSOI2010]Group 部落划分 Group (并查集)
- [二分+并查集] BZOJ1821 : [JSOI2010]Group 部落划分 Group
- 【BZOJ 1821】 [JSOI2010]Group 部落划分 Group
- bzoj 1821: [JSOI2010]Group 部落划分 Group
- 【bzoj 1821】 [JSOI2010]Group 部落划分 Group
- BZOJ 1821 Group 部落划分 Group【二分+并查集】
- bzoj1821 [JSOI2010]Group 部落划分(贪心+并查集)
- BZOJ1821 [JSOI2010]Group 部落划分 贪心+并查集
- BZOJ 1821 JSOI2010 部落划分 Group Kruskal
- bzoj 1821 [JSOI2010]Group 部落划分
- bzoj 1821: [JSOI2010]Group 部落划分
- BZOJ 1821 [JSOI2010]Group部落划分
- BZOJ 1821 [JSOI2010]Group 部落划分(kruskal)
- BZOJ 1821 [JSOI2010]Group 部落划分 Group 题解与分析
- bzoj 1821: [JSOI2010]Group 部落划分 Group Kruskal
- 1821: [JSOI2010]Group 部落划分 Group
- 1821: [JSOI2010]Group 部落划分 Group
- Linux串口c_cc[VTIME]和c_cc[VMIN]属性设置的作用
- 关于协程中yield return的一些使用
- android 字符串与bitmap的互转
- 详解 JDK JRE 和 JVM的关系
- 设置redis访问密码
- bzoj 1821: [JSOI2010]Group 部落划分 Group(并查集)
- js订单页面 判断信息 排序
- Activity和Task(栈)的关系
- 第七章 Qt事件(event)处理
- 重启网卡报Job for network.service failed because the control process exited with error code.。。 错误
- 【Html】html通过js打开新窗口或者超链接的各种方式
- 整合Spring Cloud + spring boot..分布式微服务云架构技术
- 最简单的帮你分析面相对象和面向过程!!!!!!
- ECSHOP 忘记管理员密码 重置ECSHOP管理员密码方法