题意 :
- 给一个长为 n 的序列,将其分为两个序列,定义f(x)为两个新序列的平均值之和,求f(x)的最大值。
思路 :
- 将最大的单独放在一个序列,剩余的在另一个序列。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
double a[N];
int main()
{
// IOS;
int T;
cin >> T;
while (T -- )
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ ) scanf("%lf", &a[i]);
sort(a, a + n);
double sum = 0;
for (int i = 0; i < n - 1; i ++ ) sum += a[i];
sum /= (n - 1);
printf("%.8lf\n", sum + a[n - 1]);
}
return 0;
}