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);
}

8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  2. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  3. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  4. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  5. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  6. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  7. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  8. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

  9. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

随机推荐

  1. 关于tcp连接对象在多进程中的错误:pickle.PicklingError

    如果需要在多进程中使用tcp连接的对象,那么不能再主进程中将这个对象创建好当做参数传给子进程,因为在创建子进程是需要序列化对象,然而socket对象是不能序列化的,会产生一个pickle.Pickli ...

  2. Vue基本指令

    模板对象 vue指令 一:模板对象 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  3. Python爬虫数据处理

    一.首先理解下面几个函数 设置变量 length()函数 char_length() replace() 函数 max() 函数1.1.设置变量 set @变量名=值 set @address='中国 ...

  4. 1.ubuntu的安装

    分两种 1. 在VMware中安装,则与Centos的安装类似 2. 在VirtualBox里安装 --> 1. 先“新建” 一个虚拟电脑 2. 根据需求编辑虚拟电脑的信息 (具体的大小.内存等 ...

  5. mui初探笔记

    /* MUI 使用说明: * * 1.每个用到mui的页面都调用下mui.init. * 2.如果需要使用大H5+对象,就写到plusReady中,如plus对象. */ '''[MUI开发注意事项] ...

  6. javascript方法--apply()

    今天琢磨了一下apply,以前对这个方法觉得比较懵,今天一琢磨确实觉得挺好玩的. 一开始把MDN的apply文档看了一遍,感觉不是很理解,而且有一些东西也是知道但是比较模糊,所以还是一步一步来,不懂查 ...

  7. Struts2学习笔记03 之 Result组件

    二.Result原理 1.stream 2.redirectAction 3.Json

  8. SRM 739 Div.2

    250 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostre ...

  9. 883H - Palindromic Cut(思维+STL)

    题目链接:http://codeforces.com/problemset/problem/883/H 题目大意:给一段长度为n的字符串s,想让你把s切成几段长度相同的回文串,可以改变s中字符的排列, ...

  10. 自定制Form组件

    代码 import re import copy class ValidateError(Exception): def __init__(self,detail): self.detail = de ...