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.



(1≤t≤300,2≤n≤300,1≤ai≤300)
 
Output
For each testcase, output a real number with 6 decimal places. 
 
Sample Input
2
3
1 2 3
3
100 100 100
 
Sample Output
0.500000
0.000000
 代码:
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i,j,a[9999];
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
double sum;
sum=n*(n-1);
double ans=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]>a[i])
ans++;
}
}
double p;
p=ans/sum;
printf("%.6lf\n",p);
}
return 0;
}

思路:签到水题。


hdoj5645DZY Loves Balls的更多相关文章

  1. HDU 5194 DZY Loves Balls

    DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. hdu 5645 DZY Loves Balls

    DZY Loves Balls  Accepts: 659  Submissions: 1393  Time Limit: 4000/2000 MS (Java/Others)  Memory Lim ...

  3. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  4. hdu5194 DZY Loves Balls 【概率论 or 搜索】

    //yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m ...

  5. BC#76.2DZY Loves Balls

    DZY Loves Balls  Accepts: 659  Submissions: 1393  Time Limit: 4000/2000 MS (Java/Others)  Memory Lim ...

  6. hdoj 5194 DZY Loves Balls【规律&&gcd】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5194 题意:给你n个黑球,m个白球,每次从中随机抽取一个,如果抽到黑球记为1如果抽出来白球记为0,让你 ...

  7. HDU 5645

    DZY Loves Balls Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  8. hdu 5194(DFS)

    DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. Microsoft Loves Linux

    微软新任CEO纳德拉提出的“Microsoft Loves Linux”,并且微软宣布.NET框架的开源,近期Microsoft不但宣布了Linux平台的SQL Server,还宣布了Microsof ...

随机推荐

  1. 利用gmpy2破解rsa

    gmpy2的相关文档: https://gmpy2.readthedocs.io/en/latest/ ================ 题目: 来自实验吧的rsarsa:http://www.shi ...

  2. BeanFactoryAware和BeanNameAware

    实现 BeanFactoryAware 接口的 bean 可以直接访问 Spring 容器,被容器创建以后,它会拥有一个指向 Spring 容器的引用. BeanFactoryAware 接口只有一个 ...

  3. Cable master POJ - 1064

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

  4. hdu 2433 Travel(还不会)

    Problem Description       One day, Tom traveled to a country named BGM. BGM is a small country, but ...

  5. redis:CLUSTER cluster is down 解决方法

    redis:CLUSTER cluster is down 解决方法 首先进入安装目录的src下: 1. ./redis-trib.rb check 127.0.0.1:7001 检查问题所在 2.  ...

  6. Linux下sublime的中文输入问题

    比较久了,今天找到了解决方案: git clone https://github.com/lyfeyaj/sublime-text-imfix.git cd sublime-text-imfix &a ...

  7. 单点登录 SSO, 自动登录 , java 加密,ssl原理, Tomcat配置SSL

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 单点登录的英文简称为SSO(single sign on),单点登录功能使得用户只要登录 ...

  8. 又见Python<2>:如何安装第三方库(Windows)

    使用python进行数据分析或者数据处理时,往往需要使用一些库,而使用库之前必须安装它.Anaconda内置了很多常用的第三方库,可以满足绝大部分需求,比如numpy.pandas.matplotli ...

  9. codevs 1226 倒水问题

    1226 倒水问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold   题目描述 Description 有两个无刻度标志的水壶,分别可装 x 升和 y 升 ( x, ...

  10. bzoj 4094: [Usaco2013 Dec]Optimal Milking

    4094: [Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号为1 . ...