D. Jerry's Protest
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 .

Examples
Input
2
1 2
Output
0.0000000000
Input
3
1 2 10
Output
0.0740740741
Note

In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.

In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability .

题意:每人轮流从n个数中取出一个,然后放回,数大的人获胜,A胜两场,B胜一场,但是B的总和大于A,求这种可能的概率

分析:从小到大排序之后,可以求出进行一次所有的组合,然后可以求出进行两场的组合,然后在暴力求一下比进行一次要少的两次的

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
const int Max = + ;
int cnt[Max],a[Max];
LL A[Max * ];
int main()
{
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
sort(a + , a + n + );
memset(cnt, , sizeof(cnt));
for(int i = ; i <= n; i++)
{
for(int j = i - ; j >= ; j--)
cnt[ a[i] - a[j] ]++; //每种可能的组合个数
}
int sum = n * (n - ) / ; //从n个数选择2个的总数 memset(A, , sizeof(A));
for(int i = ; i <= ; i++)
{
for(int j = ; j <= ; j++)
{
A[i + j] += (LL)cnt[i] * (LL)cnt[j]; //两场之后总和为i+j的组合数
}
} double ans = ;
for(int i = ; i <= ; i++) //胜一场的
{
for(int j = i - ; j >= ; j--) // 胜两场的总和要比胜一场的小,所以往前找
{
ans += 1.0 * cnt[i] / sum * A[j] / sum / sum; //胜一场除以sum,两场除以sum在除以sum
}
}
printf("%.10lf\n", ans);
return ;
}

codeforce626D (概率)的更多相关文章

  1. [bzoj2152][聪聪和可可] (点分治+概率)

    Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...

  2. sqlserver中根据表中的配置概率取到数据

      create proc pr_zhanglei_test1 /*功能描述: 根据t_zhanglei_test1中perc设置的概率,取到相应数据old_id */ as declare @per ...

  3. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  4. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  5. UVA1637Double Patience(概率 + 记忆化搜索)

    训练指南P327 题意:36张牌分成9堆, 每堆4张牌.每次拿走某两堆顶部的牌,但需要点数相同.如果出现多种拿法则等概率的随机拿. 如果最后拿完所有的牌则游戏成功,求成功的概率. 开个9维数组表示每一 ...

  6. caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例

    caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...

  7. 【BZOJ1415】 [Noi2005]聪聪和可可 概率与期望

    其实题不难,不知提交了几次...不能代码MD...注意一些基本问题...SB概率题 #include <iostream> #include <cstdio> #include ...

  8. 【BZOJ3036】绿豆蛙的归宿 概率与期望

    最水的概率期望,推荐算法合集之<浅析竞赛中一类数学期望问题的解决方法> #include <iostream> #include <cstdio> using na ...

  9. IT人生知识分享:概率与运气

    前言: 最近的人生多了些体验,也读了些许书,感觉还是有些知识是可以分享的. 今天难得周六,特意开电脑了,花几个小时写写,和大伙分享分享点知识. 以下内容,更多的需要读者思考,所以结论不会写太清晰,但一 ...

随机推荐

  1. 将TP引擎改为smarty引擎

    在common/config文件里设置'TMPL_ENGINE_TYPE'=>'Smarty'即可,但要注意,在模板文件里的css样式{}要用一对{literal}{/literal}标签包裹, ...

  2. MTK 平台上如何给 camera 添加一种 preview size

    1,首先检查该项目所使用的是哪一颗sensor, 就以OV2659 为例OV2659 是一颗2M 的摄像头,Sensor 吐出的数据分辨率能达到 1600*1200,肯定是支持 1280*720 的分 ...

  3. PHP基础18:require和include

    <?phph //1.通过 include 或 require 语句,可以将 PHP 文件的内容插入另一个 PHP 文件(在服务器执行它之前) //include 和 require 语句是相同 ...

  4. 反射中使用 BindingFlags.IgnoreCase

    我们经常需要通过反射来调用目标对象的方法或获取/设置目标对象的属性,Type.InvokeMember 方法签名如下: public object InvokeMember(string name,B ...

  5. 快钱支付与Sql Server的乐观锁和悲观锁

    在实际的多用户并发访问的生产环境里边,我们经常要尽可能的保持数据的一致性.而其中最典型的例子就是我们从表里边读取数据,检查验证后对数据进行修改,然后写回到数据库中.在读取和写入的过程中,如果在多用户并 ...

  6. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(2)-- 画点

    [概览] 本文实现如下的程序:(在窗体中绘画出[-100, 100]两个周期的正弦函数图像) 主要步骤如下: 1.在eric6中新建项目,新建窗体 2.(自动打开)进入PyQt5 Desinger,编 ...

  7. 《生活就像练习》读书笔记(一)——AQAL理论和象限

    摘自<生活就像练习>肯威尔伯 著 北京:同心出版社,2012.6 AQAL整合理论 AQAL的意思是“所有象限.所有层面.所有路线.所有状态.所有类型”.练习的真正目的是:努力阐释瞬息万变 ...

  8. 完美隐藏win7文件和文件夹

    有没有一种方法即使使用隐藏模式也不能查看, 没错可以用上帝模式....... 啥是Win7上帝模式?不知道的看看..... <<<<<<<<<&l ...

  9. liunx检查与安装软件包

    检查软件包# rpm -qa | grep 例如:# rpm -qa | grep make检查make包 安装软件包 yum install 例如:yum install  unixODBC安装un ...

  10. Jmeter测试webocket协议

    Jmeter本身不支持websocket协议的,所以需要安装第三方的插件还有6个依赖包. 首先,我们需要准备Jmeter的WebSocket协议的支持插件: JMeterWebSocketSample ...