E. Simple Skewness

题目连接:

http://www.codeforces.com/contest/626/problem/E

Description

Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.

The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.

The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

Output

In the first line, print a single integer k — the size of the subset.

In the second line, print k integers — the elements of the subset in any order.

If there are multiple optimal subsets, print any.

Sample Input

4

1 2 3 12

Sample Output

3

1 2 12

Hint

题意

给你n个数,然后让你选出某些数出来,使得你选出来的数的平均值减去中位数最大

题解:

暴力枚举中位数,然后二分长度

显然我们知道中位数是什么,长度是什么之后,我们直接取最大的mid个数就好了

从n开始取mid个,从中位数取mid个,这样的平均值最大嘛。

我们可以大胆猜想(不用证明),长度的那个曲线是一个单峰的,所以我们三分或者二分去做,都兹瓷。

然后这道题就完了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
long long w[maxn],s[maxn];
int n;
long long get(int x,int i)
{
return s[x]-s[x-i-1]+s[n]-s[n-i];
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&w[i]);
sort(w+1,w+1+n);
for(int i=1;i<=n;i++)
s[i]+=w[i]+s[i-1];
int ans1=1,ans2=0;
double s1=0;
for(int i=2;i<=n;i++)
{
int l=2,r=min(n-i,i-1);
int tmp=1;
while(l<=r)
{
int mid=(l+r)/2;
if(get(i,mid-1)*(2*mid+1)<get(i,mid)*(2*mid-1))
{
tmp=mid;
l=mid+1;
}
else
r=mid-1;
}
double tmp2 = 1.0*get(i,tmp)/(1.0*2*tmp+1) - 1.0*w[i];
if(tmp2>s1)
{
s1=tmp2;
ans2=tmp,ans1=i;
}
}
printf("%d\n",ans2*2+1);
for(int i=ans1;i>ans1-ans2-1;i--)printf("%d ",w[i]);
for(int i=n;i>n-ans2;i--)printf("%d ",w[i]);
printf("\n");
}

8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力

    A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...

  2. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  3. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  4. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  5. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  6. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  7. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  8. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  9. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

随机推荐

  1. 分布式队列Celery

    Celery是什么? Celery 是一个由 Python 编写的简单.灵活.可靠的用来处理大量信息的分布式系统,它同时提供操作和维护分布式系统所需的工具. Celery 专注于实时任务处理,支持任务 ...

  2. (十五)linux下gdb调试

    一.gdb常用命令: 命令 描述 backtrace(或bt) 查看各级函数调用及参数 finish 连续运行到当前函数返回为止,然后停下来等待命令 frame(或f) 帧编号 选择栈帧 info(或 ...

  3. gnu app url[web][5星]

    http://www.gnu.org/software/software.zh-cn.html http://linux.chinaunix.net/news/2010/12/07/1175310.s ...

  4. UNIX shell 学习笔记 一 : 几个shell的规则语法对比

    1. 查看系统有哪些可用的shell cat /etc/shell 2. 每种shell都有一个特殊内置变量来存上一条命令的退出状态,例: C/TC shell $status % cp fx fy ...

  5. MYSQL 索引无效和索引有效的详细介绍

    1.WHERE字句的查询条件里有不等于号(WHERE column!=...),MYSQL将无法使用索引 2.类似地,如果WHERE字句的查询条件里使用了函数(如:WHERE DAY(column)= ...

  6. linux命令(16):mv命令

    移动文件:mv /mnt/test.log /home 移动目录:mv -f /mnt/test /home [带-f参数如目的已存在同名文件,则直接覆盖掉] 文件改名:mv /mnt/test /m ...

  7. git+jenkins在windows机器上新建一个slave节点【转载】

    转至博客:上海-悠悠 前言 我们在跑自动化项目的时候,希望有单独的测试机能跑自动化项目,并且能集成到jenkins上构建任务.如果公司已经有jenkins环境了,那无需重新搭建. 只需在现有的平台基础 ...

  8. 【hdoj_2187】老人是真饿了

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2187 题意:由很多种价格的大米,在经费一定的情况下,买重量更多的大米,并且题目假设经费买不光所有的大米. ...

  9. 【机器学习】k-近邻算法以及算法实例

    机器学习中常常要用到分类算法,在诸多的分类算法中有一种算法名为k-近邻算法,也称为kNN算法. 一.kNN算法的工作原理 二.适用情况 三.算法实例及讲解 ---1.收集数据 ---2.准备数据 -- ...

  10. 前端读者 | ES6知识点概述

    本文来自 @羯瑞 整理 ES6,并不是一个新鲜的东西,ES7.ES8已经赶脚了.但是,东西不在于新,而在于总结. 变量的新定义 let 和 const 在ES6没有被普及时,我们会用的变量定义的方法是 ...