8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

D. Jerry's Protest

题目连接:

http://www.codeforces.com/contest/626/problem/D

Description

Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.

Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?

Input

The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar.

The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.

Output

Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample Input

3
1 2 10

Sample Output

0.0740740741

Hint

题意

有n个分值都不相同的球,有两个人随机拿球,谁的球的分值大谁就胜利了

他俩一共玩了三局。

A赢了两局,B赢了一局。

但是B不服,因为他三局的总分比A大。

问你这种情况发生的概率是多少。

题解:

n^2预处理之后,暴力。

我们首先预处理出A胜利两局之后所有的分差,由于球上的分数最多5000,所以分差最多就10000个。

然后我们再暴力枚举B胜利一局的分差,这个分差最多5000个。

然后我们再暴力扫一遍比B小的分数就好了,算贡献。

注意A胜利两局的方案数,会爆int

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+5;
int c1[maxn];
long long c2[maxn];
int a[maxn];
int tot,n;
double ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
        for(int j=i-1;j;j--)
            c1[a[i]-a[j]]++,tot++;
    for(int i=1;i<=5000;i++)
        for(int j=1;j<=5000;j++)
            c2[i+j]+=c1[i]*c1[j];
    for(int i=1;i<=5000;i++)
        for(int j=i-1;j;j--)
            ans+=1.0*c1[i]*c2[j]/tot/tot/tot;
    printf("%.15f\n",ans);
}
posted @ 2016-02-14 11:26  qscqesze  阅读(319)  评论(0编辑  收藏  举报