当前位置:网站首页>[training Day12] tree! Tree! Tree! [greed] [minimum spanning tree]
[training Day12] tree! Tree! Tree! [greed] [minimum spanning tree]
2022-07-25 22:30:00 【VL——MOESR】

Ideas :
We enumerate the average directly , Then use the standard deviation to sort , Do a minimum spanning tree .
But the final average should be calculated by yourself
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;
}
边栏推荐
- SMART S7-200 PLC通道自由映射功能块(DO_Map)
- Arcgis10.2 configuring postgresql9.2 standard tutorial
- ArcGIS中的WKID
- Document flow definition, box model related knowledge
- 力矩电机控制基本原理
- LabVIEW develops PCI-1680U dual port can card
- 3dslicer importing medical image data
- Flex layout
- Visitor mode
- Today, I sorted out some problems about high collapse
猜你喜欢

Fill the whole square with the float property

Multi data source switching

The third day of Xiaobai programmer

【集训DAY13】Internet【并查集】

Smart S7-200 PLC channel free mapping function block (do_map)

IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!

ThreadLocal summary (to be continued)

Use of hyperlinks

Xiaobai programmer the next day

科大讯飞智能办公本Air电纸书阅读器,让我的工作生活更加健康
随机推荐
Why is the integer type 128 to byte -128
Xiaobai programmer's fourth day
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
3day
【数据库学习】Redis 解析器&&单线程&&模型
SQL basic statement DQL select and extract DML insert delete
ThreadLocal summary (to be continued)
[leetcode] 502.ipo (difficult)
Wechat official account application development (I)
xss-工具-Beef-Xss安装以及使用
科大讯飞智能办公本Air电纸书阅读器,让我的工作生活更加健康
Google analyzes how UA can be transferred to the latest version of GA4
ML-Numpy
Synchronized and volatile
Method of converting MAPGIS format to ArcGIS
Data quality: the core of data governance
Recursive case -c
编译器引论
【集训DAY12】Minn ratio 【dfs】【最小生成树】
谷歌分析UA怎么转最新版GA4最方便