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
output
input
output
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 .

思路:暴力+概率;

每次都是独立的,我们单独看第一次,那么暴力枚举下第一次的所有的方案数,那么总的符合条件的方案就是sum^3;然后统计前两个组成的方案数,因为第三组要大于1,2两组的和,

那么我们只要枚举一二两组的和统计下前缀,然后枚举第三组,找小于第三组的就行。

复杂(N*N)

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<queue>
6 #include<string.h>
7 using namespace std;
8 int ans[3000];
9 int cnt[6000];
10 int num[6000];
11 long long sum[10005];
12 int main(void)
13 {
14 int n;
15 while(scanf("%d",&n)!=EOF)
16 { double am = 0;
17 memset(cnt,0,sizeof(cnt));
18 memset(num,0,sizeof(num));
19 int i ,j;
20 for(i = 1; i <= n; i++)
21 scanf("%d",&ans[i]);
22 for(i = 1; i <= n; i++)
23 {
24 for(j = i+1; j <=n; j++)
25 {
26 int x = abs(ans[i]-ans[j]);
27 //printf("%d\n",x);
28 num[x]++;
29 }
30 }
31 for(i = 1; i < 6000; i++)
32 {
33 cnt[i]+=cnt[i-1]+num[i];
34 }
35 memset(sum,0,sizeof(sum));
36 for(i = 1; i < 5000; i++)
37 {
38 for(j = 1; j < i; j++)
39 {
40 if(num[j]&&num[i-j])
41 {
42 sum[i]+=num[j]*num[i-j];
43 }
44 }
45 }
46 for(i = 1;i <= 5000;i++)
47 sum[i] += sum[i-1];
48 for(i = 2;i <= 5000;i++)
49 {
50 if(num[i])
51 {
52 am += sum[i-1]*num[i];
53 }
54 }
55 double maxx = cnt[5000];
56 maxx = maxx*maxx*maxx;
57
58 double an = 1.0*am/maxx;
59 printf("%.10f\n",an);
60 }
61 return 0;
62 }

codeforces626D . Jerry's Protest的更多相关文章

  1. codeforces626D . Jerry's Protest (概率)

    Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...

  2. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  3. 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 Jerr ...

  4. 数学(概率)CodeForces 626D:Jerry's Protest

    Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...

  5. Codeforces 626D Jerry's Protest 「数学组合」「数学概率」

    题意: 一个袋子里装了n个球,每个球都有编号.甲乙二人从每次随机得从袋子里不放回的取出一个球,如果甲取出的球比乙取出的球编号大则甲胜,否则乙胜.保证球的编号xi各不相同.每轮比赛完了之后把取出的两球放 ...

  6. CodeForces 626D Jerry's Protest

    计算前两盘A赢,最后一盘B赢的情况下,B获得的球的值总和大于A获得的球总和值的概率. 存储每一对球的差值有几个,然后处理一下前缀和,暴力枚举就好了...... #include<cstdio&g ...

  7. 8VC Venture Cup 2016 - Elimination Round

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

  8. codeforce626D (概率)

    D. Jerry's Protest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. 快速幂 --- CSU 1556: Jerry's trouble

    Jerry's trouble Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556 Mean: 略. ana ...

随机推荐

  1. flink-----实时项目---day04-------1. 案例:统计点击、参与某个活动的人数和次数 2. 活动指标多维度统计(自定义redisSink)

    1. 案例 用户ID,活动ID,时间,事件类型,省份 u001,A1,2019-09-02 10:10:11,1,北京市 u001,A1,2019-09-02 14:10:11,1,北京市 u001, ...

  2. Spring同一个类中的注解方法调用AOP失效问题总结

    public interface XxxService { // a -> b void a(); void b(); } @Slf4j public class XxxServiceImpl ...

  3. android:textAppearance解析

    Android的系统自带的文字外观设置及实际显示效果图 android:textAppearancexml布局里面设置文字的外观: 如"android:textAppearance=&quo ...

  4. redis入门到精通系列(三):key的通用操作和redis内部db的通用操作

    五种数据类型都用到了key,key本身是一种字符串,通过key可以获取redis中保存的对象.这一篇博客就将介绍key的通用操作. (一)key基本操作 删除key del key key是否存在 e ...

  5. ubuntu 使用mysql

    一: 安装: sudo apt-get install mysql-serversudo apt-get install mysql-clientsudo apt-get install libmys ...

  6. 使用beanUtils封装对象的servlet

    package com.hopetesting.web.servlet;import com.hopetesting.dao.UserDao;import com.hopetesting.domain ...

  7. 启动Springboot 报错 Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 12 15:50:25 CST 2019 There was an unexpected error (type=Not

    解决方案:http://www.cnblogs.com/michaelShao/p/6675186.html

  8. last显示出unknown用户

    这问题是群里有朋友发了一张照片看到的: 出现问题第一时间当然是百度或者谷歌,结果还是查到了,原来是gdm作怪,也可以认为是bug 该用户由GDM创建(可能是由于错误).并不是真的有"未知&q ...

  9. 编译工具sbt部署

    目录 一.简介 二.部署 三.测试 一.简介 项目构建工具是项目开发中非常重要的一个部分,充分利用好它能够极大的提高项目开发的效率.在学习SCALA的过程中,我遇到了SBT(Simple Build ...

  10. React中使用 react-router-dom 路由传参的三种方式详解【含V5.x、V6.x】!!!

    路由传值的三种方式(v5.x) params参数 //路由链接(携带参数): <Link to='/demo/test/tom/18'}>详情</Link> //或 <L ...