HDU 5645
DZY Loves Balls
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 320 Accepted Submission(s): 194
He has n
balls in 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 A
. Next, without putting A
back into the box, he randomly picks another ball from the box, and names it B
.
If the number written on A
is strictly greater than the number on B
, he will feel happy.
Now you are given the numbers on each ball. Please calculate the probability that he feels happy.
denoting the number of testcases.
t
testcases follow. In each testcase, first line contains n
, second line contains n
space-separated positive integers ai
, denoting the numbers on the balls.
(1≤t≤300,2≤n≤300,1≤ai≤300
)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
int n;
int a[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d",&n);
memset(a,,sizeof(a));
int jishu=;
for(int j=;j<n;j++)
scanf("%d",&a[j]);
sort(a,a+n);
for(int j=;j<n;j++)
for(int k=j+;k<n;k++)
{
if(a[k]>a[j])
jishu++;
}
double ans=n*(n-);
printf("%.6f\n",jishu/ans);
}
return ;
}
HDU 5645的更多相关文章
- HDU 5645 DZY Loves Balls 水题
DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...
- hdu 5645 DZY Loves Balls
DZY Loves Balls Accepts: 659 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- [SHELL]shell中的数学运算
一,expr 太麻烦,看的脑壳疼 二,使用方括号 !!!! bash shell用这种方法只支持整数运算,z shell倒是支持浮点型运算 var_1= var_2= var_3= my_var_1 ...
- Docker Remote API v1.24
1. Brief introduction The Remote API has replaced rcli. The daemon listens on unix:///var/run/docker ...
- Juice账号
zhangxiaocong69 zxc6545398 15657167502 区块链账户: 0x00680404766965143796a0a070835c3cdf9a4a50
- Rightmost Digit(最后一位数字)
Description Given a positive integer N, you should output the most right digit of N^N. Input The ...
- FZU.Software Engineering1816 · First Homework -Preparation
Introduction 041602204 : 我是喜欢狗狗(particularly Corgi & Shiba Inu.)的丁水源 : 我的爱好是音乐.电影.英语(100%!!!!).吉 ...
- 用URL传参带特殊字符,特殊字符丢失
文章:URL中编码URL特殊字符 文章:用URL传参带特殊字符,特殊字符丢失(encode) 如果url中有特殊字符,需要对url进行编码,否则特殊字符丢失,导致最终接收到的值不对.
- 全排列 next_permutation() 函数的用法
在头文件<algorithm>里面有如下代码: int a[]; do { } while(next_permutation(a,a+n)); 可产生1~n的全排列有如下代码: #incl ...
- YaoLingJump开发者日志(二)
熟悉了一点LGame里的套路,可以正式开工了. 增加了一个信息栏,显示得分.硬币数.生命值和当前关卡(仿照了超级玛丽的布局). 准备瑶玲的各种动画(静止.奔跑.跳跃.趴下.休息和死亡等). ...
- JS 书籍拓展内容
一.面向对象
- 老生常谈-从输入url到页面展示到底发生了什么
来自:咸鱼老弟 - 博客园 链接:http://www.cnblogs.com/xianyulaodi/p/6547807.html