codeforces626D . Jerry's Protest
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
.
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的更多相关文章
- codeforces626D . Jerry's Protest (概率)
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- 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 ...
- 数学(概率)CodeForces 626D:Jerry's Protest
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...
- Codeforces 626D Jerry's Protest 「数学组合」「数学概率」
题意: 一个袋子里装了n个球,每个球都有编号.甲乙二人从每次随机得从袋子里不放回的取出一个球,如果甲取出的球比乙取出的球编号大则甲胜,否则乙胜.保证球的编号xi各不相同.每轮比赛完了之后把取出的两球放 ...
- CodeForces 626D Jerry's Protest
计算前两盘A赢,最后一盘B赢的情况下,B获得的球的值总和大于A获得的球总和值的概率. 存储每一对球的差值有几个,然后处理一下前缀和,暴力枚举就好了...... #include<cstdio&g ...
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- codeforce626D (概率)
D. Jerry's Protest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 快速幂 --- CSU 1556: Jerry's trouble
Jerry's trouble Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556 Mean: 略. ana ...
随机推荐
- Shell【常用知识总结】
一.常用知识总结 1.特殊变量($0,@,#,*,?) $0:当前脚本的文件名. $n:n是一个数字,表示第几个参数. $#:传递给脚本或函数的参数个数. $*:传递给脚本或函数的所有参数.当被双引号 ...
- FTP 文件传输服务
昨晚心血来潮,尝试用python写了一个ftp文件传输服务,可以接收指令,从远程ftp服务器同步指定目录数据,最后没用上,开源出来. https://github.com/jadepeng/ftp_t ...
- IDEA2021.2安装与配置
https://blog.csdn.net/qq_37242720/article/details/119349394
- Template Metaprogramming in C++
说实话,学习C++以来,第一次听说"Metaprogramming"这个名词. Predict the output of following C++ program. 1 #in ...
- NSMutableArray-->NSString
1.如何把NSMutableArray 转化为NSString//用字符将NSArray中的元素拼接起来 NSArray *array = [NSArray arrayWithObjects:@&qu ...
- 远程连接mysql库问题
如果你想连接你的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL serve ...
- 【JAVA今法修真】 第四章 redis特性 击穿雪崩!
感谢这段时间大家的支持,关注我的微信号:南橘ryc ,回复云小霄,就可以获取到最新的福利靓照一张,还等什么,赶快来加入我们吧~ "明日便是决赛了,咋只会用法器没练过法术呢.". 选 ...
- 从Rest到Graphql
一.引言 ok,如图所示,我在去年曾经写过一篇文章<闲侃前后端分离的必要性>.嗯,我知道肯定很多人没看过.所以我做一个总结,其实啰里八嗦了一篇文章,就是想说一下现在的大型互联网项目一般是如 ...
- SWPUCTF_2019_login(格式字符串偏移bss段)
题目的例行检查我就不放了,将程序放入ida中 很明显的值放入了bss段的格式字符串,所以我们动态调试一下程序 可以看到ebp这个地方0xffd0dd17-->0xffd0dd38-->0x ...
- 资源相关视图(Project)
<Project2016 企业项目管理实践>张会斌 董方好 编著 这里就扯到资源了,资源是啥意思?如果是教科书,怕又是有一个名词解释要背吧,吼吼--其实这个资源在这里的意思基本上猜就能猜到 ...