太慢了,用的stl优先队列,以后用堆做一做
#include<cstdio> #include<queue> using namespace std; //用两个优先队列,保存下最大和最小的几个数 int main() { double sum = 0; int n1,n2,n,t; priority_queue<int> small; priority_queue<int,vector<int>,greater<int> > big; while(scanf("%d%d%d",&n1,&n2,&n),n1) { sum = 0; for(int i = 1;i<=n;++i) { scanf("%d",&t); sum += t; small.push(t); big.push(t); if(small.size()>n2) small.pop(); if(big.size()>n1) big.pop(); } while(!small.empty()) { sum -= small.top(); small.pop(); } while(!big.empty()) { sum -= big.top(); big.pop(); } printf("%.6f\n",sum/(1.0*(n-n1-n2))); } return 0; }