当前位置:网站首页>【集训DAY12】树!树!树!【贪心】【最小生成树】
【集训DAY12】树!树!树!【贪心】【最小生成树】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们直接枚举平均数,然后用求出标准差来排序,做一遍最小生成树。
但最后的平均数还是要自己算
c o d e code code
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
long long bj[100010],fa[100010];
double maxn,ans=1e18;
long long n,m;
struct node
{
double w,b;
int x,y;
}a[200010];
bool cmp(node&x,node&y)
{
return x.b<y.b;
}
int find(int faa)
{
if(fa[faa]==faa)
return faa;
return fa[faa]=find(fa[faa]);
}
double kruskal()
{
double js=0;
for(int i=1; i<=n; i++)
fa[i]=i;
for(int i=1; i<=m; i++)
{
bj[i]=0;
int fx=find(a[i].x),fy=find(a[i].y);
if(fx!=fy)
{
bj[i]=1,fa[fx]=fy;
js+=a[i].w;
}
}
double p=js/(n*1.0-1.0),anss=0;
for(int i=1; i<=m; i++)
if(bj[i])
anss+=(a[i].w-p)*(a[i].w-p);
return sqrt(anss/(n*1.0-1.0));
}
int main()
{
scanf("%lld%lld",&n,&m);
for(int i=1; i<=m; i++)
{
scanf("%lld%lld%lf",&a[i].x,&a[i].y,&a[i].w);
maxn=max(a[i].w,maxn);
}
for(double i=0; i<=maxn; i+=0.1)
{
for(int j=1; j<=m; j++)
a[j].b=(a[j].w-i)*(a[j].w-i);
sort(a+1,a+1+m,cmp);
ans=min(ans,kruskal());
}
printf("%.4lf",ans);
return 0;
}
边栏推荐
- 3dslicer importing medical image data
- How many bytes does Boolean occupy?
- MySQL --- 子查询 - 列子查询(多行子查询)
- Smart S7-200 PLC channel free mapping function block (do_map)
- 谷歌分析UA怎么转最新版GA4最方便
- Div drag effect
- Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
- Fill the whole square with the float property
- [C syntax] void*
- 启牛商学院和微淼商学院哪个靠谱?老师推荐的开户安全吗?
猜你喜欢

Usage of in in SQL DQL query

Xiaobai programmer's sixth day

Using simple scripts to process data in 3dslicer

MySQL - subquery - column subquery (multi row subquery)

还不懂mock测试?一篇文章带你熟悉mock

Don't vote, software testing posts are saturated

xss-工具-Beef-Xss安装以及使用

Win10 set up a flutter environment to step on the pit diary

Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture

LabVIEW 开发 PCI-1680U双端口CAN卡
随机推荐
数据平台下的数据治理
D3.js 学习
Data governance under data platform
Why is the integer type 128 to byte -128
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc
Method of converting MAPGIS format to ArcGIS
SQL basic statement DQL select and extract DML insert delete
编译和反编译
字符型常量和字符串常量的区别?
Gan, why '𠮷 𠮷'.Length== 3 ??
How to call the size of two numbers with a function--- Xiao Tang
【集训DAY15】简单计算【树状数组】【数学】
H5 lucky scratch lottery free official account + direct operation
Basic principle of torque motor control
scrapy无缝对接布隆过滤器
ThreadLocal 总结(未完待续)
Five constraints and three paradigms
JSP novice
[database learning] redis parser & single thread & Model
4day