杭电5645之DZY Loves Balls
来源:互联网 发布:unity3d 引擎 编辑:程序博客网 时间:2024/06/07 21:59
Problem Description
DZY loves playing balls.
He hasn 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 itA . Next, without putting A back into the box, he randomly picks another ball from the box, and names it B .
If the number written onA 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.
He has
One day he decides to pick two balls from the box. First he randomly picks a ball from the box, and names it
If the number written on
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.
(1≤t≤300,2≤n≤300,1≤ai≤300 )
(
Output
For each testcase, output a real number with 6 decimal places.
Sample Input
231 2 33100 100 100Sample Output0.5000000.000000问题描述DZY喜欢玩球。他有n个球,装进一个大盒子里。每个球上面都写着一个整数。有一天他打算从盒子中挑两个球出来。他先均匀随机地从盒子中挑出一个球,记为A。他不把A放回盒子,然后再从盒子中均匀随机地挑出一个球,记为B。如果A上的数字严格大于B上的数字,那么他就会感到愉悦。现在告诉你每个球上的数字,请你求出他感到愉悦的概率是多少。输入描述第一行t,表示有t组数据。接下来t组数据。每组数据中,第一行包含一个整数n,第二行包含n个用空格隔开的正整数ai,表示球上的数字。(1≤t≤300,2≤n≤300,1≤ai≤300)输出描述对于每个数据,输出一个实数答案,保留6位小数。输入样例231 2 33100 100 100输出样例0.5000000.000000分析:把所有球两两比较,第一个球大于第二个球的情况除以总情况n*(n-1),即得答案AC代码如下:#include "stdio.h"int main(int argc, char* argv[]){int n,i,j,m,a[301],num;double res;scanf("%d",&n);while(n--){num=0;scanf("%d",&m);for (i=0;i<m;i++){scanf("%d",&a[i]);}for (i=0;i<m;i++){for (j=0;j<m;j++){if (a[i]>a[j]){num++;//记录A>B的情况}}}res=(double)num/(m*(m-1));printf("%lf\n",res);}return 0;}
0 0
- 杭电5645之DZY Loves Balls
- 【杭电】[5645]DZY Loves Balls
- 杭电5194DZY Loves Balls
- hdu 5645 DZY Loves Balls
- HDOJ 5645 DZY Loves Balls
- HDU 5645 DZY Loves Balls
- hdu 5645 DZY Loves Balls
- HDOJ 5645 DZY Loves Balls
- hdoj-5645-DZY Loves Balls
- HDU 5645 DZY Loves Balls
- HDOJ 5645-DZY Loves Balls【模拟】
- HDOJ 5645 DZY Loves Balls (概率)
- HDU 5645 DZY Loves Balls(概率)
- hdu 5645 DZY Loves Balls 概率
- hdu DZY Loves Balls
- DZY Loves Balls
- DZY Loves Balls
- HDU 5194 DZY Loves Balls
- 几句话讲清 JS 闭包
- Name node is in safe mode 解决办法
- jrMz and angles 暴力
- 优化加载和执行提高javascript性能
- MyBatis分页的简单实现
- 杭电5645之DZY Loves Balls
- 二叉搜索树的插入和删除结点操作以及iterator的构造
- SpringMVC个人零碎总结
- 手机浏览器上的特殊效果,如拨号、跳转地图app等
- HDOJ -- 1061 Rightmost Digi
- 1587 - Box
- Java 键树---字典树(小词典)的实现
- jQuery 怎么实现点击页面其他地方隐藏菜单?
- 深入理解java虚拟机(三):String.intern()-字符串常量池