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. GSON转换日期数据为特定的JSON数据

    通过JSON传递数据的时候经常需要传递日期,Java中可以通过GSON将日期转换为特定格式的JSON数据. 1.普通的GSON转换日期 public void query(HttpServletReq ...

  2. php中的转义函数

    <?php parse_url 解析URL, 返回各组成部分 urlencode/urldecode url编码/解码 htmlentities 将字符串转化为html实体 htmlentiti ...

  3. Django框架<一>

    Django框架 Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Sess ...

  4. $fhqTreap$

    - $fhqTreap$与$Treap$的差异 $fhqTreap$是$Treap$的非旋版本,可以实现一切$Treap$操作,及区间操作和可持久化 $fhqTreap$非旋关键在于分裂与合并$(Sp ...

  5. php7.33 configure

    To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for desc ...

  6. HTML表格的基本操作

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  7. POJ 2431 Expedition (贪心 + 优先队列)

    题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...

  8. 找到最大或最小的N个元素---heapq模块

    堆排序heapq的用法 基本用法: 复杂数据结构: # coding=utf- # example.py # Example of using heapq to find the N smallest ...

  9. lr获取响应结果中的乱码并转成中文

    {,"message":"楠岃瘉鐮侀敊璇\xAF","developerMessage":"楠岃瘉鐮侀敊璇\xAF"} ...

  10. 十三oracle --控制结构(分支,循环,控制)

    .使用各种if语句2.使用循环语句3.使用控制语句——goto和null(goto语句不推荐使用): 二.条件分支语句pl/sql中提供了三种条件分支语句if—then,if–then–else,if ...