博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5645 DZY Loves Balls(概率)
阅读量:4137 次
发布时间:2019-05-25

本文共 1430 字,大约阅读时间需要 4 分钟。

DZY Loves Balls

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 661 Accepted Submission(s): 389
Problem Description
DZY loves playing balls.
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.
Input
First line contains
t 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.
(
1t300,2n300,1ai300 )
Output
For each testcase, output a real number with 6 decimal places.
Sample Input
231 2 33100 100 100
Sample Output
0.5000000.000000  
/*思路:对求号码进行排序 取两次球第一次不放回,所有可能的情况为n*(n-1),对于每一个球,枚举比他大的球的位置j,n-j即为比第一次球大的数目a,a/(n*(n-1)),即为每一次的概率,累加即为结果 */#include
#include
#include
using namespace std;const int N=300+5;int a[N];int main(){ int t,i,j,n; double re; cin>>t; while(t--){ cin>>n; re=0; for(i=0;i
>a[i]; sort(a,a+n); for(i=0;i

转载地址:http://gbmvi.baihongyu.com/

你可能感兴趣的文章
kk音标导读(下):赖世雄老师26个英语字母导读示范 (附我备注)
查看>>
赖世雄精准美国英语音标发音指南01 (附我备注)
查看>>
赖世雄精准美国英语音标发音指南02 (附我备注)
查看>>
赖世雄精准美国英语音标发音指南03 (附我备注)
查看>>
赖世雄精准美国英语音标发音指南04(附我备注)
查看>>
《过得刚好》 郭德纲
查看>>
fork函数详解(fork就是分叉的意思, 很形象)
查看>>
那一年, fork() 函数弄晕了多少Windows程序猿
查看>>
以亲身感受浅谈程序的注释和一个bug的代价(单位:RMB)
查看>>
当printf("-")遇上fork() ---某公司招聘笔试题目
查看>>
谢孟媛老师英语音标发音01(附我备注)
查看>>
谢孟媛老师英语音标发音02(附我备注)
查看>>
如何用C语言判断ip地址是否合法? (用inet_addr有问题)
查看>>
《随遇而安》 孟非
查看>>
如何引用另外一个文件中的串, 顺便说说void print();和(void)print();的区别
查看>>
今天第一次面试别人, 大概聊了近30分钟
查看>>
我经历的那些骗局(要承认, 骗子智商比我们高)
查看>>
C语言一个文件中的函数能直接调用另外一个文件中的静态函数吗? (某公司校园招聘面试试题)
查看>>
有“空洞”的文件的C代码实现
查看>>
简单详解:x^6+4x^4+2x^3+x+1 至少要需要多少次乘法? (某公司实习生招聘笔试试题)
查看>>