poj2833
用两个数组来存最大值和最小值,每次用冒泡的方式维护。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
#define maxn 20
int n1, n2, n;
int f1[maxn], f2[maxn];
void up1(int f[], int x)
{
for (int i = x - 1; i >= 0; i--)
{
if (f[i] < f[i + 1])
swap(f[i], f[i + 1]);
}
}
void up2(int f[], int x)
{
for (int i = x - 1; i >= 0; i--)
{
if (f[i] > f[i + 1])
swap(f[i], f[i + 1]);
}
}
int main()
{
//freopen("D:\\t.txt", "r", stdin);
while (scanf("%d%d%d", &n1, &n2, &n) != EOF && !(n1 == 0 && n2 == 0 && n == 0))
{
long long sum = 0;
for (int i = 0; i < n; i++)
{
int a;
scanf("%d", &a);
sum += a;
if (i < n1)
f1[i] = a;
else if (a > f1[n1 - 1])
{
f1[n1 - 1] = a;
up1(f1, n1 - 1);
}
if (i < n2)
f2[i] = a;
else if (a < f2[n2 - 1])
{
f2[n2 - 1] = a;
up2(f2, n2 - 1);
}
}
for (int i = 0; i < n1; i++)
sum -= f1[i];
for (int i = 0; i < n2; i++)
sum -= f2[i];
printf("%.6f\n", sum / double(n - n1 - n2));
}
return 0;
}