当前位置:网站首页>【集训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;
}
边栏推荐
- Method of converting MAPGIS format to ArcGIS
- arcgis开发常用源码
- SQL中in的用法 DQL 查询
- 微信发卡小程序源码-自动发卡小程序源码-带流量主功能
- 3day
- scrapy无缝对接布隆过滤器
- [C syntax] void*
- Title: give a group of arrays, arranged from large to small and from small to large.
- Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
- Math programming classification
猜你喜欢

『Skywalking』. Net core fast access distributed link tracking platform

How to implement an app application to limit users' time use?

什么是分区分桶?

【集训DAY15】简单计算【树状数组】【数学】

H5 lucky scratch lottery free official account + direct operation

Don't vote, software testing posts are saturated

xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)

沃达德软件:智慧城市方案

What is partition and barrel division?

ML-Numpy
随机推荐
Flex layout
What is partition and barrel division?
How to implement an app application to limit users' time use?
Matrix of C language
MySQL - subquery - column subquery (multi row subquery)
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
PySpark数据分析基础:pyspark.sql.SparkSession类方法详解及操作+代码展示
Redis memory elimination mechanism?
Google analyzes how UA can be transferred to the latest version of GA4
MapGIS格式转ArcGIS方法
ML-Numpy
Short circuit effect of logical operators short circuit and short circuit or
Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
Synchronized and volatile
QML module not found
『SignalR』. Net using signalr for real-time communication
QML module not found
IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!
【集训DAY15】Boring【树形DP】
Wkid in ArcGIS