Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4437 Accepted Submission(s): 1561
Problem Description King OMeGa catched three men who had been streaking in the street. Looking as idiots though, the three men insisted that it was a kind of performance art, and begged the king to free them. Out of hatred to the real idiots, the king wanted to check if they were lying. The three men were sent to the king's forest, and each of them was asked to pick a branch one after another. If the three branches they bring back can form a triangle, their math ability would save them. Otherwise, they would be sent into jail. However, the three men were exactly idiots, and what they would do is only to pick the branches randomly. Certainly, they couldn't pick the same branch - but the one with the same length as another is available. Given the lengths of all branches in the forest, determine the probability that they would be saved.
Input An integer T(T≤100) will exist in the first line of input, indicating the number of test cases. Each test case begins with the number of branches N(3≤N≤105). The following line contains N integers a_i (1≤a_i≤105), which denotes the length of each branch, respectively.
Output Output the probability that their branches can form a triangle, in accuracy of 7 decimal places.
Sample Input 2 4 1 3 3 4 4 2 3 3 4
Sample Output 0.5000000 1.0000000
Source 2013 Multi-University Training Contest 1 -----------------------------------------------------------. 题目大意: 就是跟你 N 个数代表长度为a_i的木棒,现在问你随便拿出来三个就能构成三角形的概率为多少
解题思路: 首先考虑暴力的 就是求 a_i-a_j<k <a_i+a_j满足题意的这样的值有多少个,那么这样的话,我们就需要知道,这 N 个数两两加的和是什么样的,计算出这个之后,我们在预处理出前缀和之后就可以通过枚举最长边来O(n)计算三角形的情况数,再除以C_{n}^{3}=\frac{n*(n-1)*(n-2)}{6}就是概率了,
所以最严重的问题就是如何求这 N 个数的两两相加。 这时候如果把加法换成乘法那么就可以转化为向量相乘,用 FFT 就可以o(nlog_2n)解决了