题目链接

给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. kafka学习(四)-Topic & Partition

    topic中partition存储分布 Topic在逻辑上可以被认为是一个queue.每条消费都必须指定它的topic,可以简单理解为必须指明把这条消息放进哪个queue里.为了使得 Kafka的吞吐 ...

  2. xmanager 使用

    linux 上安装xterm windows上启动命令: /usr/bin/xterm -ls -display $DISPLAY

  3. 大写String和小写string的区别

    1.string是c#中的类,String是.net Framework的类(在c# IDE中不会显示蓝色) ; 2.c# string映射为.net Framework的String ; 3.如果用 ...

  4. google base库之simplethread

    // This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...

  5. [非技术参考]C#重写ToString方法

    C# 中的每个类或结构都隐式继承 Object 类. 因此,C# 中的每个对象都会获得 ToString 方法,此方法返回该对象的字符串表示形式. 例如,所有 int 类型的变量都有一个 ToStri ...

  6. leetcode Contains Duplicate II python

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  7. [翻译]如何用YII写出安全的WEB应用

    前言 虽然本文是基于YII1.1,但其中提到的安全措施适用于多数web项目安全场景,所以翻译此文,跟大家交流.原文地址. 目录 安全基本措施... 2 验证与过滤用户的输入信息... 2 原理... ...

  8. shell中常用的特殊字符

    (1) * 代表0到无穷个任意字符 (2)?代表任意一个字符 (3)代表括号内任意一个字符 (4)[ - ] 代表一个范围中的任意一个字符 如[0-9] 即是代表0-9之间的一个数 (5)[^] 反向 ...

  9. SQL 设计心得、逗号分隔列表

    第一: 在开始编码前.主要关注数据库里要保存什么样的数据,以级最佳的数据组织方式和内在关联方式. 第二: 使用你所知的数据库特性尽可能高效的实现数据管理.如正确的索引.数据库类型.高效的select! ...

  10. 苹果iPhone不能判断红外发射管的好坏

    用手机来检测红外发射管好坏是目前比较常用的方法.实际操作比较简单,就是按照红外发射管的工作电压给发射管接上电源后,把手机的摄像头对着红外发射管就能看出好坏了.由于红外线是肉眼看不见的,如果不通过手机摄 ...