计算前两盘A赢,最后一盘B赢的情况下,B获得的球的值总和大于A获得的球总和值的概率。
存储每一对球的差值有几个,然后处理一下前缀和,暴力枚举就好了......
#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<vector> #include<queue> #include<algorithm> #include<iostream> using namespace std; const int maxn = 5000 + 10; int n; int a[maxn]; int b[maxn]; int sum[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(sum, 0, sizeof sum); memset(b, 0, sizeof b); sort(a+1, a + n+1); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) b[a[j] - a[i]]++; double ans = 0; for (int i = 1; i <= 5000; i++) sum[i] = sum[i - 1] + b[i]; for (int i = 0; i <= 5000; i++) for (int j = 0; j <= 5000; j++) { if (i + j <= 5000) ans = ans + 1.0*b[i] * b[j] * (sum[5000] - sum[i + j]); } // printf("%d ", ans); double N = (double)n; double f = N*(N - 1)*N*(N - 1)*N*(N - 1) / 8.0; printf("%.6lf ", 1.0*ans / f); return 0; }