记录编号 377288 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 中位数 最终得分 100
用户昵称 Gravatarrewine 是否通过 通过
代码语言 C++ 运行时间 0.681 s
提交时间 2017-03-01 08:18:43 内存使用 3.04 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>

int n,a[250010];

#define max(a,b) (a>b?a:b)

void read(int &x) {
    char c;bool flag = 0;
    while((c=getchar())<'0'||c>'9') flag |= (c=='-');
    x=c-'0';while((c=getchar())>='0'&&c<='9') x = x*10+c-'0';
    flag?x=-x:x;
}

int main() {
    freopen("median.in","r",stdin);freopen("median.out","w",stdout);
	scanf("%d",&n);
	int mid = n/2+1;
	for (int i = 1; i <= mid; i++)
	  read(a[i]),std::push_heap(a+1,a+i+1);
	int k;
	for (int i = mid+1; i <= n; i++) {
	    read(a[mid+1]);
		std::push_heap(a+1,a+mid+2);
		std::pop_heap(a+1,a+mid+2);
	}
	if(n&1) printf("%.1f",(double)a[1]);
	else printf("%.1f",(a[1]+max(a[2],a[3]))/2.0);
    return 0;
}