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. 【Python学习】使用BeautifulSoup解析HTML

    对于一个最简单的爬虫结构的代码是这样的. 也就是抓取出整个页面,然后创建一个BeautifulSoup对象. from urllib.request import urlopen from bs4 i ...

  2. 新装linux系统最基本设置

    1,dns设置:vi /etc/resolv.conf   添加内容:nameserver 8.8.8.8 2,vi设置: vi ~/.bashrc  添加内容:alias vi='vim': 然后执 ...

  3. mysql的一些规范

    我司的mysql规范,值得牢记 一.禁止内容 表字段类型 不推荐使用enum,set,blob,text等类型 表中所有字段都不能为空,需要设置not null属性,可以给默认值 表的主键列值禁止被更 ...

  4. ProxySQL 故障

    发现直接连接MGR节点是正常的,可以写入,但通过ProxySQL连接就无法show\select\insert 等 使用sysbench对ProxySQL报以下错误: FATAL: `thread_r ...

  5. 56.Merge Intervals---贪心---《编程之美》2.19区间重合判断

    题目链接:https://leetcode.com/problems/merge-intervals/description/ 题目大意:给出一串list,里面装interval类,这个类里有star ...

  6. .pnts点云

    一种3d tiles格式 MIME格式: <configuration> <system.webServer> <staticContent> <remove ...

  7. before_request after_request

    Flask我们已经学习很多基础知识了,现在有一个问题 我们现在有一个 Flask 程序其中有3个路由和视图函数,如下: from flask import Flask app = Flask(__na ...

  8. 使用亚马逊云服务器EC2做深度学习(三)配置TensorFlow

    这是<使用亚马逊云服务器EC2做深度学习>系列的第三篇文章. (一)申请竞价实例  (二)配置Jupyter Notebook服务器  (三)配置TensorFlow  (四)配置好的系统 ...

  9. python和shell间变量互相传递

    Python -> shell: 参考文章 1.环境变量 import os var=123或var=’123’ os.environ[’var’]=str(var) #environ的键值必须 ...

  10. 解决序列化类型为“System.Reflection.RuntimeModule”的对象时检测到循环引用。

    定义一个继承JavaScriptConverter的子类 public class DataTableConverter : JavaScriptConverter { /// <summary ...