题目链接

给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 三分的更多相关文章

  1. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

  2. Codeforces 626E Simple Skewness 「数学」「二分」

    题意: 给你一堆无序数,寻找它的一个子堆,使得子堆的平均数减中位数最大. 数字的个数n<=2e5 0<=xi<=1e6. 思路: 首先可以证明这堆数一定是奇数个,证明方法是尝试在奇数 ...

  3. codeforces626E.Simple Skewness(三分)

    Define the simple skewness of a collection of numbers to be the collection's mean minus its median. ...

  4. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  5. 【CodeForces 626E】Simple Skewness

    题意 给出n个数的集合,求一个 (平均数-中位数)最大 (偏度最大)的子集,输出子集元素个数和各个元素(任意顺序). 分析 因为是子集,所以不一定是连续的序列.然后我们有下面几个结论. 1.最大偏度一 ...

  6. CodeForces - 344B Simple Molecules (模拟题)

    CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...

  7. CodeForces 570B Simple Game 概率

    原题: http://codeforces.com/contest/570/problem/B 题目: Simple Game time limit per test1 second memory l ...

  8. codeforces 962F.simple cycle(tarjan/点双连通分量)

    题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...

  9. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

随机推荐

  1. Android学习路线(六)为Android应用加入ActionBar

    Action bar 是你可以为你的应用的Activity实现的最为重要的设计元素之中的一个.它提供了集中UI特性.而且通过提供和其它的Android应用的一致性体验让你的应用可以非常快被用户熟悉.基 ...

  2. VB6关于判断模态窗体的问题

    模态窗体也有人叫模式窗体,是否为模态窗体由Show方法的参数决定: 语法 object.Show style, ownerform Show 方法的语法包含下列部分: 部分 描述 object 可选的 ...

  3. Objective-C官方文档翻译 Block

    版权声明:原创作品,谢绝转载!否则将追究法律责任. 一个Objective-c类定义了一个对象结合数据相关的行为.有时候,这使得他有意义的表达单个任务或者单元的行为.而不是集合的方法. blocks是 ...

  4. javascript中this指针的认识

    javascript中上下文环境就是this指针,即被调用函数所处的环境.这个上下文环境在大多数情况下指的是函数运行时封装这个函数的那个对象:当不通过任何对象单独调用一个函数时,上下文环境指的就是全局 ...

  5. scanf函数和printf函数

    C程序实现输出和输入的 主要是printf函数 和 scanf函数,这两个函数是格式输入输出 格式声明由%和格式字符组成 如%d,%f 格式字符:  d格式符:用来输出一个有符号的十进制整数  c格式 ...

  6. mina学习资料整合

    最好的资料当然是官方文档:https://mina.apache.org/mina-project/userguide/user-guide-toc.html 官方文档,配合源码中的example例子 ...

  7. mysql errno:13

    新装的mysql,创建表时报错误 errno:13,网上查了一下是权限问题.解决方式如下: 到mysql的数据目录下:即启动进程中:--datadir=/data/soft/mysql/mysqlda ...

  8. 常用笔记: JS实现VBS当中的Replace

    <script> //JS实现VBS当中的Replace,替换全部.方法名大写,区别于原方法,与VBS相类似. String.prototype.Replace = function(ol ...

  9. Exception in MessageQueue callback: handleReceiveCallback

    07-20 14:27:11.477: E/InputEventReceiver(7209): Exception dispatching input event. 07-20 14:27:11.47 ...

  10. clip原理

    1.clip的概述: clip是修剪之意 clip有4个属性值:inherit auto rect(20px,40px,60px,0px) !important 其中有作用的仅rect这个属性值,着重 ...