DZY Loves Balls

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5645

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

Hint

题意

有n个球,你首先拿一个球A,然后不放回,再拿一个球B

问你球A大于球B的概率是多少

题解:

数据范围很小,直接暴力就好了

nlogn的话,写个权值线段树/树状数组就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 301;
int a[maxn];
void solve()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
double ans = 0;
for(int i=1;i<=n;i++)
{
int add = 0;
for(int j=1;j<=n;j++)
if(a[i]>a[j])add++;
ans=ans+add;
}
printf("%.6f\n",ans/((1.0*n*(n-1))));
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
}

HDU 5645 DZY Loves Balls 水题的更多相关文章

  1. hdu 5645 DZY Loves Balls

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

  2. HDU 5194 DZY Loves Balls

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

  3. hdu 5268 ZYB loves Score 水题

    ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  4. hdu 5272 Dylans loves numbers 水题

    Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...

  5. HDU 5655 CA Loves Stick 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 CA Loves Stick Accepts: 381   Submissions: 3204 ...

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

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

  7. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  8. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  9. HDU 5590 ZYB's Biology 水题

    ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

随机推荐

  1. module 'pytest' has no attribute 'allure'问题解决

    安装allure后执行命令后报错module 'pytest' has no attribute 'allure' C:\Users\Desktop\xin>pytest -s -q --all ...

  2. PXC加入新节点避免SST时grastate.dat文件内容的修改问题

    PXC加入新节点避免SST时grastate.dat文件内容的修改问题 在主从同步完成并关闭实例后,需要修改grastate.dat中的seqno:到底应该填已经执行过最后的XID号(Executed ...

  3. 2017 CERC

    2017 CERC Problem A:Assignment Algorithm 题目描述:按照规则安排在飞机上的座位. solution 模拟. 时间复杂度:\(O(nm)\) Problem B: ...

  4. yum和head一起用,报错“由于管道被破坏而退出”

    当要打印 [yum list ]时, 加上了管道符 以及 head 会出现报错 “由于管道被破坏而退出” 是因为 yum 与 head 连用 存在bug ,如果使用tail 则没有出现 具体什么bug ...

  5. php+mysql缓存技术的实现

    本教程适合于那些对缓存SQL查询以减少数据库连接与执行的负载.提高脚本性能感兴趣的PHP程序员.概述 许多站点使用数据库作为站点数据存储的容器.数据库包含了产器信息.目录结构.文章或者留言本,有些数据 ...

  6. javaScript如何跳出多重循环break、continue

    先来说说break和continue之间的区别 for(var i=0;i<10;i++){  if(i>5){  break;  }}console.log(i);  ---6  •当i ...

  7. Mysql查询语句的运行流程

    我们先看一下MYsql的基本架构示意图: 大体来说,MySQL 可以分为 Server 层和存储引擎层两部分. Server 层包括连接器.查询缓存.分析器.优化器.执行器等,涵盖 MySQL 的大多 ...

  8. JMeter -----响应时间设置

    当压力增大会出现connect timeout error. 解决办法:http request default--advance--timeouts 如填写10,表示大于10ms报错.

  9. AC日记——830A - Office Keys

    思路: 背包: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <ios ...

  10. 在Docker中自定义Jenkins镜像

    一. 构建Jenkins slave. 1. 构建镜像需要三个步骤: (1) 创建Dockerfile (2) 构建镜像 (3)在master上改变agent的配置 2. 以下是创建一个服务Pytho ...