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 ...
随机推荐
- 搭建FastDFS集群
先插一张图(学习的时候找的)http://blog.csdn.net/u012453843/article/details/68957209?> 软件下载地址:主要是fastdfs.libfas ...
- MySQL全面瓦解29:使用Partition功能实现水平分区
1 回顾 上一节我们详细讲解了如何对数据库进行分区操作,包括了 垂直拆分(Scale Up 纵向扩展)和 水平拆分(Scale Out 横向扩展) ,同时简要整理了水平分区的几种策略,现在来回顾一下. ...
- 零基础学习java------21---------动态代理,java8新特性(lambda, stream,DateApi)
1. 动态代理 在一个方法前后加内容,最简单直观的方法就是直接在代码上加内容(如数据库中的事务),但这样写不够灵活,并且代码可维护性差,所以就需要引入动态代理 1.1 静态代理实现 在讲动态代理之前, ...
- 内存中 1k 代表什么
1K也就是 1KB == 1000 bytes == 1000 *8 位 通常一个地址里面有8位,就是说一个房间里面能存8个0或者1
- 双向循环链表模板类(C++)
双向链表又称为双链表,使用双向链表的目的是为了解决在链表中访问直接前驱和后继的问题.其设置前驱后继指针的目的,就是为了节省其时间开销,也就是用空间换时间. 在双向链表的每个节点中应有两个链接指针作为它 ...
- 【STM32】使用SDIO进行SD卡读写,包含文件管理FatFs(三)-SD卡的操作流程
其他链接 [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(一)-初步认识SD卡 [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(二)-了解SD总线,命令的相关介绍 ...
- 通过Shell统计PV和UV
PV.UV是网站分析中最基础.最常见的指标.PV即PageView,网站浏览量,指页面的浏览次数,用以衡量网站用户访问的网页数量.用户没打开一个页面便记录1次PV,多次打开同一页面则浏览量累计:UV即 ...
- 【力扣】649. Dota2 参议院
Dota2 的世界里有两个阵营:Radiant(天辉)和 Dire(夜魇) Dota2 参议院由来自两派的参议员组成.现在参议院希望对一个 Dota2 游戏里的改变作出决定.他们以一个基于轮为过程的投 ...
- 【Spark】【复习】Spark入门考前概念相关题复习
Spark考前概念相关题复习 AUthor:萌狼蓝天 哔哩哔哩:萌狼蓝天 博客园:我的文章 - 萌狼蓝天 博客:萌狼工作室 - 萌狼蓝天 (mllt.cc) 选择题 Hadoop 1.HADOOP的三 ...
- C# 获取当前目录的父级目录
Directory.GetParent(System.Environment.CurrentDirectory).FullName