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 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 .
Sample Input
3
1 2 10
Sample Output
0.0740740741
Hint
题意
有n个分值都不相同的球,有两个人随机拿球,谁的球的分值大谁就胜利了
他俩一共玩了三局。
A赢了两局,B赢了一局。
但是B不服,因为他三局的总分比A大。
问你这种情况发生的概率是多少。
题解:
n^2预处理之后,暴力。
我们首先预处理出A胜利两局之后所有的分差,由于球上的分数最多5000,所以分差最多就10000个。
然后我们再暴力枚举B胜利一局的分差,这个分差最多5000个。
然后我们再暴力扫一遍比B小的分数就好了,算贡献。
注意A胜利两局的方案数,会爆int
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+5;
int c1[maxn];
long long c2[maxn];
int a[maxn];
int tot,n;
double ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
for(int j=i-1;j;j--)
c1[a[i]-a[j]]++,tot++;
for(int i=1;i<=5000;i++)
for(int j=1;j<=5000;j++)
c2[i+j]+=c1[i]*c1[j];
for(int i=1;i<=5000;i++)
for(int j=i-1;j;j--)
ans+=1.0*c1[i]*c2[j]/tot/tot/tot;
printf("%.15f\n",ans);
}
8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力的更多相关文章
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre
C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp
F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分
C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
随机推荐
- 利用Python 发送邮件
概要 我们都知道SMTP(简单邮件传输协议),是一组用于从原地址到目的地址传输邮件的规范,通过它来控制邮件的中转方式.SMTP规定电子邮件应该如何格式化.如何加密,以及如何在邮件服务器之间传递.SMT ...
- python写一段脚本代码自动完成输入(目录下的所有)文件的数据替换(修改数据和替换数据都是输入的)【转】
转自:http://blog.csdn.net/lixiaojie1012/article/details/23628129 初次尝试python语言,感觉用着真舒服,简单明了,库函数一调用就OK了 ...
- Redis 分片实现 Redis Shard [www]
Redis 分片实现 Redis Shard https://www.oschina.net/p/redis-s ...
- [New learn] 手势
1.简介 我们经常会在设备上查看图片等, 也会经常将图片通过手指的捏合打开来缩小和方法图片.这就是ios中的手势功能在起作用. 那么手势好像也是一种touch事件,那和UIResponder中定义的t ...
- Cent os FTP配置
原文:http://www.aicoffees.com/itshare/412261137.html
- 关于Free的override不能省略的问题,切记,虚方法是可以被覆盖的方法。
- 禅道BUG管理工具使用链接存储
http://www.zentao.net/book/zentaopmshelp/259.html
- Java学习笔记(十三)——通过Netbeans开发环境生成oracle数据库中表的对应hibernate映射文件
[前面的话] 身体慢慢已经快好了,感觉真好,哈哈. 这篇文章要通过Hibernate对数据库进行操作,而Netbeans可以直接通过数据库逆向生成对应的映射文件.基础文章,选择性阅读. [步骤] 1. ...
- MSSQL为单独数据库创建登录账户
如果要为一个数据库创建一个独立的账号需要这个数据库为包含数据库 当前(非包含)的数据库所面临的问题在描述什么是包含数据库之前,先了解一下为什么会出现包含数据库.当前的数据库有一些问题,如下:1.在数据 ...
- NodeJs中使用jQuery?
在NodeJs中使用jQuery? 有时候在项目中需要使用jq在node中,但是使用起来却不是那么友好,那么现在该怎么做?改写JQ插件?将JQ插件打包成npm包,再在项目中进行引用?显然这些相比较于难 ...