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. Linux汇编教程01: 基本知识

    在我们开始学习Linux汇编之前,需要简单的了解一下计算机的体系结构.我们不需要特别深入的了解,理解了一些基本概念对与我们理解程序会很有帮助.现在计算机的结构体系都是采用冯诺依曼体系结构的基础上发展过 ...

  2. Windows 10又现新Bug,24核心竟卡成蜗牛

    Windows 10又现新Bug,24核心竟卡成蜗牛 https://news.cnblogs.com/n/573996/

  3. Canvas开发库封装

    一.Canvas第三方类库 1.常见的第三方类库 konva.js <style> body{ margin:0; } </style> </head> <b ...

  4. ubuntu在vim编辑时,方向键无法正常使用

    /* 如果在普通用户下. */ [frankie@localhost ~]$ sudo apt-get install vim [frankie@localhost ~]$ cd /etc/vim [ ...

  5. springmvc中输出字符串

    /** * 输出文字 * @param response * @param s */ public static void responseOut(HttpServletResponse respon ...

  6. RabbitMQ 基础知识

    1. 背景 RabbitMQ 是一个由 erlang 开发的AMQP 开源实现,erlang语言天生具备高并发的特性,而且他的管理界面用起来十分方便. 基础概念 讲解基础概念的前面,我们先来整体构造一 ...

  7. MYSQL有外键无法删除

    今天删除数据库中数据,提示因为设置了foreign key,无法修改删除 可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况. SET FOREIGN_KEY_CHECKS=0; 删除 ...

  8. Java中的原子操作类

    转载: <ava并发编程的艺术>第7章 当程序更新一个变量时,如果多线程同时更新这个变量,可能得到期望之外的值,比如变量i=1,A线程更新i+1,B线程也更新i+1,经过两个线程操作之后可 ...

  9. connect-falsh的用法

    借鉴博客 http://yunkus.com/connect-flash-usage/

  10. 自定义wordCount程序、

    1.MyWordCount代码: package com.hadoop.mr; import java.io.IOException; import org.apache.hadoop.conf.Co ...