DZY Loves Balls

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 320    Accepted Submission(s): 194

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
 
Source
昨天参加了蓝桥  感觉不是很理想 等出结果吧
补 前天的bc
因为数据规模很小,所以直接用O(n2)​​)时间求出有多少对(i,j)满足ai<aj,然后再除以n(n−1)/2即可。
 
 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
int n;
int a[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d",&n);
memset(a,,sizeof(a));
int jishu=;
for(int j=;j<n;j++)
scanf("%d",&a[j]);
sort(a,a+n);
for(int j=;j<n;j++)
for(int k=j+;k<n;k++)
{
if(a[k]>a[j])
jishu++;
}
double ans=n*(n-);
printf("%.6f\n",jishu/ans);
}
return ;
}

HDU 5645的更多相关文章

  1. HDU 5645 DZY Loves Balls 水题

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

  2. hdu 5645 DZY Loves Balls

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

  3. HDU 2159 FATE(二维费用背包)

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 389. Valid Sudoku【LintCode java】

    Description Determine whether a Sudoku is valid. The Sudoku board could be partially filled, where e ...

  2. LeetCode 144 ——二叉树的前序遍历

    1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 将当前节点的数值加入到 data 中 递归得到其左子树的数据向量 temp,将 te ...

  3. solidity python 签名和验证

    注意,以太坊智能合约里面采用的是公钥非紧凑类型 def gen_secrets_pair(): """ 得到公钥和私钥 :return: ""&quo ...

  4. js经典试题之w3规范系列

    js经典试题之w3规范系列 1:w3c 制定的 javascript 标准事件模型的正确的顺序? 答案:事件捕获->事件处理->事件冒泡 解析:先事件捕获从windows > doc ...

  5. Thunder团队第三周 - Scrum会议6

    Scrum会议6 小组名称:Thunder 项目名称:i阅app Scrum Master:宋雨 工作照片: 代秋彤照相,所以图片中没有该同学. 参会成员: 王航:http://www.cnblogs ...

  6. Android 网络编程 API笔记 - java.net 包相关 接口 api

    Android 网络编程相关的包 : 9 包, 20 接口, 103 类, 6 枚举, 14异常; -- Java包 : java.net 包 (6接口, 34类, 2枚举, 12异常); -- An ...

  7. 福州大学软工1816 | K班 第一次作业

    (一)回想一下你初入大学时对计算机专业的畅想 (1)当初你是如何做出选择计算机专业的决定的? 本身对于计算机感兴趣.高考完之后翻了书,对于物理数学等基础学科兴趣不大,对金融等商科几乎毫无了解,再加上当 ...

  8. ejabberd学习1

    ejabberd是XMPP协议的一个实现,对大家的另一个意义就是,可以通过ejabberd来学习erlang. 1.从源码安装ejabberd. 可以参考ejabberd 简明配置.这个博文包括了安装 ...

  9. OSG学习:转动的小汽车示例

    由于只是简单的示例,所以小汽车的模型也比较简单,是由简单的几何体组成. 代码如下: #include <osg\ShapeDrawable> #include <osg\Animat ...

  10. 原生js实现自定义alert风格和实现

    2018年6月29 最新更新 添加函数节流,解决多次点击问题,添加单例模式,提高代码性能. <!DOCTYPE html> <html lang="en"> ...