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. 集合类---set

    定义:一个不包含重复元素的collection.set 不包含满足 e1.equals(e2) 的元素对 e1 和 e2,并且最多包含一个 null 元素,不保证集合里元素的顺序. 方法使用详解: 1 ...

  2. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  3. Kettle提高输入输出数据总结

    1 mysql在数据连接是可以通过设置一下三个三处的方式 useServerPrepStmts=false       useCursorFetch=true      useCompression= ...

  4. Jquery屏蔽浏览器的F1-F12快捷键,在IE,GOOGLE下测试均无问题

    在网上找了找,很多都是js实现的,东找西找,再加上自己的想法也勉强的完成了,直接看代码 <script type="text/javascript" src="Sc ...

  5. Binary Tree Level Order Traversal&&II

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  6. Graph Cut 简介

    转:http://www.cnblogs.com/longdouhzt/archive/2012/05/11/2496373.html [简介] Graph Cuts 不等于 graph cut(如 ...

  7. AC日记——小B的询问 洛谷 P2709

    小B的询问 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 50005 #define ll ...

  8. 将xml文件转为c#对像

    读取xml文件数据,通过序列化反序列化转为List<T>对象后,对对象进行操作.

  9. Openstack 网络服务 Neutron计算节点部署 (十一)

    一) Neutron计算节点部署 1.安装软件包 # yum install -y openstack-neutron-linuxbridge ebtables ipset 2.配置文件neutron ...

  10. 【笔试题】Java 易错题精选

    笔试题 Java 易错题精选 1.写出下列程序的运行结果( )String 不变性Java 值传递 public class Test { public static void main(String ...