标签:ted include math number win first key ranch acm
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10153 Accepted Submission(s):
3448
#include <bits/stdc++.h> using namespace std; const int maxn = 262144; struct comp{ double x, y; comp(double _x = 0, double _y = 0){ x = _x; y = _y; } friend comp operator * (const comp &a, const comp &b){ return comp(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); } friend comp operator + (const comp &a, const comp &b){ return comp(a.x + b.x, a.y + b.y); } friend comp operator - (const comp &a, const comp &b){ return comp(a.x - b.x, a.y - b.y); } }f[maxn]; int rev[maxn]; void dft(comp A[], int len, int kind){ for(int i = 0; i < len; i++){ if(i < rev[i]){ swap(A[i], A[rev[i]]); } } for(int i = 1; i < len; i <<= 1){ comp wn(cos(acos(-1.0) / i), kind * sin(acos(-1.0) / i)); for(int j = 0; j < len; j += (i << 1)){ comp tmp(1, 0); for(int k = 0; k < i; k++){ comp s = A[j + k], t = tmp * A[i + j + k]; A[j + k] = s + t; A[i + j + k] = s - t; tmp = tmp * wn; } } } if(kind == -1) for(int i = 0; i < len; i++) A[i].x /= len; } void init(int &len){ int L = 0; for(len = 1; len < maxn; len <<= 1, L++); for(int i = 0; i < len; i++){ rev[i] = rev[i >> 1] >> 1 | (i & 1) << L - 1; } } int a[maxn], val[maxn] = {0}; long long num[maxn]; int main(){ int t; scanf("%d", &t); int len; init(len); while(t--){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", a + i); val[a[i]]++; } for(int i = 0; i < len; i++){ f[i].x = val[i]; } dft(f, len, 1); for(int i = 0; i < len; i++) f[i] = f[i] * f[i]; dft(f, len, -1); for(int i = 1; i < len; i++) num[i] = (long long)(f[i].x + 0.5); for(int i = 1; i <= n; i++){ num[a[i] << 1]--; } for(int i = 1; i < len; i++) num[i] = num[i] >> 1; num[0] = 0; for(int i = 1; i < len; i++) num[i] += num[i - 1]; long long ans = 0; for(int i = 1; i <= n; i++){ ans += num[a[i]]; } printf("%.7lf\n", 1 - 6.0 * ans / n / (n - 1) / (n - 2)); for(int i = 1; i <= n; i++) val[a[i]]--; for(int i = 0; i < len; i++) f[i] = comp(); } return 0; }
标签:ted include math number win first key ranch acm
原文地址:https://www.cnblogs.com/ruoruoruo/p/11782321.html