0.500000
0.000000
一道求期望的水题~~~~~~~~~~~~~~~~~~~~~~~~~·
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int t, sq[1000], n;
bool cmp(int x, int y)
{
return x < y;
}
int same(int x) {
if((x + 1) < n && sq[x] == sq[x + 1])
return 1 + same(x + 1);
return 0;
}
int main()
{
scanf("%d", &t);
while (t--) {
double ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &sq[i]);
}
sort(sq, sq + n,cmp);
for (int i = 0; i < n; i++) {
if(same(i)) {
ans += n -1 - i - same(i);
}
else ans += n - i - 1;
}
printf("%lf\n", ans / (n * (n - 1)));
}
return 0;
}