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. java 数组的基本概念

    1.数组的基本概念 数组指的是一组相关变量的集合.例如:如果说现在要定义100个整型变量,如果按照我们以前的思路,我们可能这样定义: public class demo { public static ...

  2. asp.net core结合Gitlab-CI实现自动化部署

    0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 一.前言 在之前的文章中写过k8s+Jenkins+GitLab-自动化部署asp.net core项目 的topic,这次讲解一 ...

  3. 【8.20校内测试】【DP】【二分+贪心】

    一开始想的贪心,可是发现贪心的问题太多了啊!只能保证当前最优,全局完全无法考虑. 所以正解是dp.预处理出前缀和,枚举每个区间,在每个点记录$now[i]$表示以$i$这个塔结尾的塔组目前的高度.$d ...

  4. 线段树 求区间连乘——hdu 3074 Multiply game

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. VK Cup 2016 - Round 1 (Div. 2 Edition) D. Bear and Polynomials

    D. Bear and Polynomials 题目连接: http://www.codeforces.com/contest/658/problem/D Description Limak is a ...

  6. 设计模式 - 观察者模式(Observer Pattern) Java内置 用法

    观察者模式(Observer Pattern) Java内置 用法 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26601659 ...

  7. 关于GCC Cygwin MinGW MSYS

    [转载]关于Gcc/MinGW/Cygwin/Msys http://blog.sciencenet.cn/blog-778757-616920.html 一.GCC的历史 GCC是一个原本用于Uni ...

  8. MySql清空表的方法介绍 : truncate table 表名

    清空某个mysql表中所有内容 delete from 表名; truncate table 表名; 不带where参数的delete语句可以删除mysql表中所有内容,使用truncate tabl ...

  9. java多线程知识点汇总(二)多线程实例解析

    本实验主要考察多线程对单例模式的操作,和多线程对同一资源的读取,两个知识.实验涉及到三个类: 1)一个pojo类Student,包括set/get方法. 2)一个线程类,设置student的成员变量a ...

  10. iTunes Connect App Bundles

    App Bundles捆绑销售提交流程: 1. 在iTunes Connect左上「+」选「Create Bundle」到「New App Bundle」挑选已上线应用(最多可捆绑10个应用) 2. ...