题目链接
….见题号吧
题意
就是说有n个评分,裁判系统需要减去n1个最高分和n2个最低分,然后求出平均分.
n1+n2
题解
由于题给的内存大小为10000kb,而一个5,000,000的数组需要4*5000000* b = 20000kb
会超出内存限制于是,不能存5000000数组
我们想到用2个优先队列模拟n1个最大值,和n2个最小值
最后用所有得分的总和减去n1个最大值和n2个最小值.再除以个数.就是平均值.
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
priority_queue<ll,vector<int>,less<int> > small; ///最大堆 -> 弹出最大值,保留最小n2个
priority_queue<ll,vector<int>,greater<int> > big; ///最小堆 -> 弹出最小值,保留最大n1个
int main()
{
int n1,n2,n;
while(~scanf("%d%d%d",&n1,&n2,&n),n1+n2+n)
{
ll ans = 0;
for(int i=0,x;i<n;i++) {
scanf("%d",&x);
ans += x;
small.push(x);if(small.size() > n2) small.pop();
big.push(x);if(big.size() > n1) big.pop();
}
ll temp = 0;
while(!small.empty()) temp += small.top(),small.pop();
while(!big.empty()) temp += big.top(),big.pop();
printf("%.6f\n",1.0*(ans-temp)/(n-n1-n2));
}
return 0;
}