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. java中的Arrays类

    今天刚接触了数组,学到了几个比较常用的方法 Fill方法:给数组赋值 sort方法:给数组升序 equals方法:比较数组中元素 值是否相等 binarySearch方法:对排序好的数组进行二分查找法 ...

  2. 数据库之JDBC

    1.简单认识一下JDBC 1).JDBC是什么? java database connection       java数据库连接 作用:就是为了java连接mysql数据库嘛 要详细的,就面向百度编 ...

  3. 一起手写吧!sleep函数!

    Async/Await 版本 function sleep(delay) { return new Promise(reslove => { setTimeout(reslove, delay) ...

  4. [php代码审计] 通读审计之shangfancms

    前言 大部分的MVC框架,访问的控制器大部分是由外部参数来决定的,那么本篇文章所通读的MVC框架与之前的一系列MVC框架不太一样,它的路由是由程序本身的路由表来决定的. 源码下载 https://ww ...

  5. 容器之分类与各种测试(四)——unordered-multimap

    unordered-multiset与unordered-multimap的区别和multiset与multimap的区别基本相同,所以在定义和插入时需要注意 key-value 的类型. 例程 #i ...

  6. 容器之分类与各种测试(三)——stack

    stack是栈,其实现也是使用了双端队列(只要不用双端队列的一端,仅用单端数据进出即完成单端队列的功能),由于queue和stack的实现均是使用deque,没有自己的数据结构和算法,所以这俩也被称为 ...

  7. 100个Shell脚本—【脚本6】拷贝目录

    [脚本6]拷贝目录 编写shell脚本,把/root/目录下的所有目录(只需要一级)拷贝到/tmp/目录下: 一.脚本 #!/bin/bash cd /root list=(`ls`) for i i ...

  8. Camera、音频录制与Vitamio框架

    一.Camera 1.概述 Android框架包含了各种相机哥相机功能的支持,是你可以在应用中捕获图像和视频. 在应用能使用设备上的相机之前,先想一想将来会如何使用此硬件: (1)Camera  应该 ...

  9. 错误: 找不到或无法加载主类(IDEA中启动spring boot项目)

    版权声明:本文为博主原创文章,如果转载请给出原文链接:http://www.jufanshare.com/content/142.html 提示:需要对IDEA编辑工具使用熟悉 出现一个问题,就是sp ...

  10. windows 查看端口被占用,解除占用

    查看 (列举端口为2688) netstat -ano | findstr "2688" 解除 原文地址