# 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness（枚举+三分）★

491人阅读 评论(0)

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 1000100
#define MOD 1000000007

int n,m;
int a[maxn];
long long sum[maxn];

int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,C = 1;
//scanf("%d",&t);
while(scanf("%d",&n) != EOF)
{
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
sum[0] = 0;
for(int i = 1; i <= n; i++)
sum[i] = sum[i-1] + a[i];
long long pos = 1,len = 0;
long long ans = 0;
for(int i = 2; i < n; i++)
{
long long l = 1, r = min(i-1, n - i);
long long mid, mmid;
for(int j = 1; j <= 100; j++)
{
mid = (2*l + r) / 3;
mmid = (l + 2*r + 2) / 3;
long long m1 = (sum[i] - sum[i-mid-1] + sum[n] - sum[n-mid]);
long long m2 = (sum[i] - sum[i-mmid-1] + sum[n] - sum[n-mmid]);
if(m2*(mid*2+1) <= m1*(mmid*2+1))
r = mmid - 1;
else
l = mid + 1;
}
double cur = (double)(sum[i] - sum[i-l-1] + sum[n] - sum[n-l]) - (2*l+1)*a[i];
if(ans*(2*l+1) < cur*(2*len+1))   //为了避免精度问题， 转化为整数比较
{
ans = cur;
len = l;
pos = i;
}
}
printf("%lld\n",len*2+1);
for(int i = pos - len; i <= pos; i++)
printf("%d ",a[i]);
for(int i = n-len+1; i <= n; i++)
printf("%d%c",a[i],i==n?'\n':' ');
}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：99078次
• 积分：4178
• 等级：
• 排名：第7361名
• 原创：306篇
• 转载：187篇
• 译文：0篇
• 评论：1条
最新评论