codeforce626D (概率)
2 seconds
256 megabytes
standard input
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?
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.
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
.
2
1 2
0.0000000000
3
1 2 10
0.0740740741
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 (概率)的更多相关文章
- [bzoj2152][聪聪和可可] (点分治+概率)
Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...
- sqlserver中根据表中的配置概率取到数据
create proc pr_zhanglei_test1 /*功能描述: 根据t_zhanglei_test1中perc设置的概率,取到相应数据old_id */ as declare @per ...
- 【BZOJ-3143】游走 高斯消元 + 概率期望
3143: [Hnoi2013]游走 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2264 Solved: 987[Submit][Status] ...
- 【BZOJ-3270】博物馆 高斯消元 + 概率期望
3270: 博物馆 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 292 Solved: 158[Submit][Status][Discuss] ...
- UVA1637Double Patience(概率 + 记忆化搜索)
训练指南P327 题意:36张牌分成9堆, 每堆4张牌.每次拿走某两堆顶部的牌,但需要点数相同.如果出现多种拿法则等概率的随机拿. 如果最后拿完所有的牌则游戏成功,求成功的概率. 开个9维数组表示每一 ...
- caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例
caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...
- 【BZOJ1415】 [Noi2005]聪聪和可可 概率与期望
其实题不难,不知提交了几次...不能代码MD...注意一些基本问题...SB概率题 #include <iostream> #include <cstdio> #include ...
- 【BZOJ3036】绿豆蛙的归宿 概率与期望
最水的概率期望,推荐算法合集之<浅析竞赛中一类数学期望问题的解决方法> #include <iostream> #include <cstdio> using na ...
- IT人生知识分享:概率与运气
前言: 最近的人生多了些体验,也读了些许书,感觉还是有些知识是可以分享的. 今天难得周六,特意开电脑了,花几个小时写写,和大伙分享分享点知识. 以下内容,更多的需要读者思考,所以结论不会写太清晰,但一 ...
随机推荐
- 两种方式判断类的存在→className getAttribute
通过className获取 var p = document.getElementsByTagName('p'); for(var i = 0;i <p.length;i++){ if(p[i] ...
- <global-results>怎么用
<global-results>中的result可以被所有action跳转,所有action都可以跳转到result 所有返回值为“json”的action,都可以跳转到json.jsp
- 24Spring_事务管理机制
第一部分:Spring事务管理高层抽象接口 我们介绍三个接口:1.PlatformTransactionManager 2.TransactionDefinition 3.TransactionSt ...
- ubuntu中启用ssh服务
ssh程序分为有客户端程序openssh-client和服务端程序openssh-server.如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...
- 变态跳台阶-一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
class Solution { public: int jumpFloorII(int number) { ) ; ) ; *jumpFloorII(number-); } };
- php基础30:正则匹配-量词
<?php //正则表达式 //1.第一个正则表达式 if("a"=="a"){ echo "equal"; }else{ echo ...
- .NET面试题解析(07)-多线程编程与线程同步 (转)
http://www.cnblogs.com/anding/p/5301754.html 系列文章目录地址: .NET面试题解析(00)-开篇来谈谈面试 & 系列文章索引 关于线程的知识点其实 ...
- 九度oj-1003-Java
题目描述: 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开. 现在请计算A+B的结果,并以正常形式输出. 输入: 输入包含多组数据数据,每组数据占一行,由两 ...
- [MetaHook] Quake Bink function
If you want to play Bink video in game, maybe you need this code. QBink.h #ifndef QBINK_H #define QB ...
- MVC5 + EF6 + Bootstrap3 (12) 新建数据
Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-create.html 系列教程:MVC5 + EF6 + ...