博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力
阅读量:6887 次
发布时间:2019-06-27

本文共 2309 字,大约阅读时间需要 7 分钟。

D. Jerry's Protest

题目连接:

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

转载地址:http://irtbl.baihongyu.com/

你可能感兴趣的文章
SQL 去重
查看>>
ubuntu 设置静态IP
查看>>
linux文档的压缩与打包
查看>>
百度贴吧爬虫程序
查看>>
如何卸载失效的vCenter插件
查看>>
GPFS通用并行文件系统之Centos5.8部署gpfs集群
查看>>
SqlHelper:带sqlParameter,对sql server增、册、查、改的公用方法
查看>>
【Exchange 2019 設置技巧】用戶郵箱默認配額設定
查看>>
centos虚拟机实现上网
查看>>
我的友情链接
查看>>
处理HP-UNIX面板灯报警及配置MP
查看>>
Java多线程和线程池
查看>>
配置docker使用overlay2存储
查看>>
邮件服务器迁移方案让企业邮箱安心“搬家”
查看>>
SCDPM常见报错解答
查看>>
OA项目笔记
查看>>
引用计数 vs. GC
查看>>
jquery实用的一些方法
查看>>
质数方阵
查看>>
jQuery $.each用法
查看>>