codeforces 626E. Simple Skewness 三分
给n个数, 让你去掉一些数, 使得剩下的数的平均值-中位数的差值最大。
先将数组排序, 然后枚举每一个数作为中位数的情况, 对于每个枚举的数, 三分它的左右区间长度找到一个平均值最大的情况, 平均值最大, 肯定是它左边的数是靠近他的那几个数, 右边的数是最右边的那几个数。 然后所有情况取最大值。
三分的写法lmid = (l*2+r)/2, rmid = (l+r*2+2)/3, 学到了。
并且求平均值最好不要除,比如说平均数-中位数, 那么写成 这几个数的和-中位数*长度。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 2e5+;
ll a[maxn], sum[maxn];
int n;
ll cal(int len, int pos) {
ll num = sum[pos]-sum[pos-len-]+sum[n]-sum[n-len];
return num;
}
int main()
{
cin>>n;
for(int i = ; i<=n; i++) {
scanf("%I64d", &a[i]);
}
if(n == || n == ) {
cout<<<<endl;
cout<<a[]<<endl;
return ;
}
sort(a+, a++n);
ll maxx = ;
int len = , mid = ;
for(int i = ; i<=n; i++)
sum[i] = sum[i-]+a[i];
for(int i = ; i<=n-; i++) {
int l = , r = min(i-, n-i);
while(l<r) {
int lmid = (*l+r)/;
int rmid = (l+*r+)/;
ll ans1 = cal(lmid, i);
ll ans2 = cal(rmid, i);
if(ans1*(*rmid+)<(*lmid+)*ans2) {
l = lmid+;
} else {
r = rmid-;
}
}
ll tmp = (sum[i]-sum[i-l-]+sum[n]-sum[n-l])-(*l+)*a[i];
if(tmp*(*len+)>maxx*(*l+)) {
maxx = tmp;
len = l;
mid = i;
}
}
cout<<*len+<<endl;
for(int i = mid-len; i<=mid; i++)
printf("%d ", a[i]);
for(int i = n-len+; i<=n; i++)
printf("%d ", a[i]);
return ;
}
codeforces 626E. Simple Skewness 三分的更多相关文章
- Codeforces 626E Simple Skewness(暴力枚举+二分)
E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces 626E Simple Skewness 「数学」「二分」
题意: 给你一堆无序数,寻找它的一个子堆,使得子堆的平均数减中位数最大. 数字的个数n<=2e5 0<=xi<=1e6. 思路: 首先可以证明这堆数一定是奇数个,证明方法是尝试在奇数 ...
- codeforces626E.Simple Skewness(三分)
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 【CodeForces 626E】Simple Skewness
题意 给出n个数的集合,求一个 (平均数-中位数)最大 (偏度最大)的子集,输出子集元素个数和各个元素(任意顺序). 分析 因为是子集,所以不一定是连续的序列.然后我们有下面几个结论. 1.最大偏度一 ...
- CodeForces - 344B Simple Molecules (模拟题)
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...
- CodeForces 570B Simple Game 概率
原题: http://codeforces.com/contest/570/problem/B 题目: Simple Game time limit per test1 second memory l ...
- codeforces 962F.simple cycle(tarjan/点双连通分量)
题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
随机推荐
- 杂记之activity之间的跳转
代码结构图 manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xml ...
- HDU 4715 Difference Between Primes (打表)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 转换成CSV文件、Word、Excel、PDF等的方法--读取CSV文件的方法
1. 转换成CSV文件: http://www.dotnetgallery.com/lab/resource93-Export-to-CSV-file-from-Data-Table-in-Aspne ...
- Cisco Packet Tracer的使用(一)
Cisco Packet Tracer 是由Cisco公司发布的一个辅助学习工具,为学习思科网络课程的初学者去设计.配置.排除网络故障提供了网络模拟环境.用户可以在软件的图形用户界面上直接使用拖曳方法 ...
- spring aop简单日志实例
转载自:http://www.blogjava.net/laoding/articles/242611.html 一直就用spring的IOC,遗憾spring的另一重要组成部分AOP却没用过,所以近 ...
- 红豆带你从零学C#系列之:开始C#编程(二)
控制台程序开发之补充说明 你已经动手操作过我们上一篇文章中的控制台程序输入输出了吗朋友? 如果没有的话,强烈建议你先回去做一遍再来继续学习噢!上一篇文章地址:点击这里 一. 你问我答 问:代码是 ...
- rownum(转载)
对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between...and,只能用以上符号(<.<=.!=),并非说用>,>=,=,be ...
- c#Ulong用一个高位Uint和低位Uint表示
有时候考虑到平台之间的通用性,可能把一个Ulong拆分成2个Uint来进行各平台之间的通讯,当时转换的时候有点头晕,对与或预算不是很熟悉,不过还是花了半小时弄出来了,代码: //ulong的最大值2^ ...
- BZOJ 3110: [Zjoi2013]K大数查询( 树状数组套主席树 )
BIT+(可持久化)权值线段树, 用到了BIT的差分技巧. 时间复杂度O(Nlog^2(N)) ---------------------------------------------------- ...
- jaspersoft 5.6.0 相关问题
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true" ...