BestCoder Round #76 (div.2) DZY Loves Balls
2016-03-19 20:53
357 查看
DZY Loves Balls
Accepts: 662 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Problem DescriptionDZY loves playing balls.He has nn ballsin a big box. On each ball there is an integer written.One day he decides to pick two balls from the box. First he randomly picks a ball from the box, and names it AA.Next, without putting AA backinto the box, he randomly picks another ball from the box, and names it BB.If the number written on AA isstrictly greater than the number on BB,he will feel happy.Now you are given the numbers on each ball. Please calculate the probability that he feels happy.InputFirst line contains tt denotingthe number of testcases.tt testcasesfollow. In each testcase, first line contains nn,second line contains nn space-separatedpositive integers a_iai,denoting the numbers on the balls.(1\let\le 300, 2\le n \le 300,1\le a_i \le 3001≤t≤300,2≤n≤300,1≤ai≤300)OutputFor each testcase, output a real number with 6 decimal places.Sample Input2 3 1 2 3 3 100 100 100Sample Output
0.500000 0.000000
一道求期望的水题~~~~~~~~~~~~~~~~~~~~~~~~~·
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int t, sq[1000], n;bool cmp(int x, int y){return x < y;}int same(int x) {if((x + 1) < n && sq[x] == sq[x + 1])return 1 + same(x + 1);return 0;}int main(){scanf("%d", &t);while (t--) {double ans = 0;scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%d", &sq[i]);}sort(sq, sq + n,cmp);for (int i = 0; i < n; i++) {if(same(i)) {ans += n -1 - i - same(i);}else ans += n - i - 1;}printf("%lf\n", ans / (n * (n - 1)));}return 0;}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- 高精度加法——杭电1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006