EOJ Monthly 2019.2 (based on February Selection) F.方差
题目链接:
https://acm.ecnu.edu.cn/contest/140/problem/F/
题目:

思路:

因为方差是用来评估数据的离散程度的,因此最优的m个数一定是排序后连续的,所以我们可以先排序然后对每m个连续的数取个min。
代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 1e6 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, m;
int a[maxn];
LL sum1[maxn], sum2[maxn]; int main(){
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + , a + n + );
for(int i = ; i <= n; i++) {
sum1[i] = sum1[i-] + a[i];
sum2[i] = sum2[i-] + a[i] * a[i];
}
LL ans = INF;
for(int i = ; i <= n - m + ; i++) {
ans = min(ans, m * (sum2[i+m-] - sum2[i-]) - (sum1[i+m-] - sum1[i-]) * (sum1[i+m-] - sum1[i-]));
}
printf("%lld\n", ans);
return ;
}
EOJ Monthly 2019.2 (based on February Selection) F.方差的更多相关文章
- EOJ Monthly 2019.2 (based on February Selection) D.进制转换
题目链接: https://acm.ecnu.edu.cn/contest/140/problem/D/ 题目: 思路: 我们知道一个数在某一个进制k下末尾零的个数x就是这个数整除kx,这题要求刚好末 ...
- EOJ Monthly 2019.2 (based on February Selection) D 进制转换 【数学 进制转换】
任意门:https://acm.ecnu.edu.cn/contest/140/problem/D/ D. 进制转换 单测试点时限: 2.0 秒 内存限制: 256 MB “他觉得一个人奋斗更轻松自在 ...
- EOJ Monthly 2019.2 题解(B、D、F)
EOJ Monthly 2019.2 题解(B.D.F) 官方题解:https://acm.ecnu.edu.cn/blog/entry/320/ B. 解题 单测试点时限: 2.0 秒 内存限制: ...
- EOJ Monthly 2019.11 E. 数学题(莫比乌斯反演+杜教筛+拉格朗日插值)
传送门 题意: 统计\(k\)元组个数\((a_1,a_2,\cdots,a_n),1\leq a_i\leq n\)使得\(gcd(a_1,a_2,\cdots,a_k,n)=1\). 定义\(f( ...
- EOJ Monthly 2019.2
题解 A 回收卫星 #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/s ...
- EOJ Monthly 2019.1 唐纳德先生与这真的是签到题吗 【数学+暴力+multiset】
传送门:https://acm.ecnu.edu.cn/contest/126/ C. 唐纳德先生与这真的是签到题吗 单测试点时限: 6.0 秒 内存限制: 1024 MB 唐纳德先生在出月赛的过程中 ...
- EOJ Monthly 2019.3 A
A. 钝角三角形 单点时限: 3.0 sec 内存限制: 512 MB QQ 小方以前不会判断钝角三角形,现在他会了,所以他急切的想教会你. 如果三角形的三边长分别为 a, b, c (a≤b≤c), ...
- eoj monthly 2019.11
原题 T1 纸条 题目大意: 给出一个长度为n的字符串,其中m位未知,对于每一位未知的字母,有k个备选字母,最终答案为备选字母按字典序排序后的第x个. 题解: 签到题-- 按照题目意思直接写就可以了. ...
- EOJ Monthly 2019.2 E. 中位数 (二分+dfs)
题目传送门 题意: 在一个n个点,m条边的有向无环图中,求出所有从1到n 的路径的中位数的最大值 一条路径的中位数指的是:一条路径有 n 个点, 将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋ ...
随机推荐
- python 菜鸟入门
python 菜鸟博客: http://www.cnblogs.com/wupeiqi/articles/5433893.html http://www.cnblogs.com/linhaifeng/ ...
- pyqt5 eric6
1 安装Anaconda3 2 python环境变量改为Anaconda3中python 3 pip安装pyqt5 ,pip安装pyqt5-tool 其中tool中包含eric6 ui文件必须使用的d ...
- [微软官方]FSUTIL
Applies To: Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows Server 2003 ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- [OS] Linux进程、线程通信方式总结
转自:http://blog.sina.com.cn/s/blog_64b9c6850100ub80.html Linux系统中的进程通信方式主要以下几种: 同一主机上的进程通信方式 * UNIX进程 ...
- IE Only的userData
上次我们提到了本地存储的一个方式,那就是Cookie,不过遗憾的是Cookie保存的数据量非常小,更详细的可以参考<在 Internet Explorer 中的 cookie 的数字和大小限制& ...
- sqlserver查询数据库中包含某个字段的所有表和所有存储过程
1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的 ...
- springmvc+mybatis 根据数据的id删除数据
1. 数据库表 2. notices.jsp <form action="#" method="post"> <fieldset> &l ...
- Divisibility by 25 CodeForces - 988E(模拟)
遇见模拟题 有两种做法 例如这题: 1.直接去算次数(统计哪个数在第几位,然后去运算) 2.模拟操作 贴一个别人的代码...https://blog.csdn.net/weixin_39453270/ ...
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...