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. 【WXS数据类型】Function

    属性: 名称 值类型 说明 [Function].constructor [String] 返回值为“Function”,表示类型的结构字符串 [Function].length [Number] 返 ...

  2. 手机端网页返回顶部js代码

    <!DOCTYPE html>  <html>  <head>  <meta http-equiv="Content-Type" cont ...

  3. Memcache的客户端连接系列(二) Python

    关键词: Memcached   Python 客户端 声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南.客户端连接方法通用,故摘抄过来分享给大家. Python ...

  4. 【MySQL解惑笔记】忘记MySQL数据库密码

    破解MySQL密码 一.MySQL5.7.5之前 只要有系统root密码就可以破解: [root@host- ~]# vim /etc/my.cnf //在配置文件中加入如下内容 [mysqld] s ...

  5. ubuntu 18.04 LTS server系统安装失败问题解决

    准备自己搭一个服务器,USB引导盘的方式安装ubutun系统. 中途遇到两个问题,导致耗时比较久,记录如下. 问题一: installing system阶段卡主 具体描述: 配置镜像源地址以后,进入 ...

  6. maven 安装、配置

    简介: maven 大大提高项目开发速度     编译---打包---测试--安装   一条龙 maven将项目构建的过程标准化,每一个阶段使用一个命令完成,下面是构建过程一些阶段 清理 mvn cl ...

  7. python常用命令—终端安装win32的两种方法

    1, pip install pywin32 2, pip install pypiwin32

  8. LeetCode 169. Majority Element - majority vote algorithm (Java)

    1. 题目描述Description Link: https://leetcode.com/problems/majority-element/description/ Given an array ...

  9. location 匹配规则 (NGINX)

    转:https://moonbingbing.gitbooks.io/openresty-best-practices/ngx/nginx_local_pcre.html location 匹配规则 ...

  10. C中文件操作的文本模式和二进制模式,到底有啥区别?

    在C中,使用fopen打开文件有两种模式:一种是文本模式,一种是二进制模式.那这两种模式之间有什么区别,是不是使用文本模式打开的文件就只能使用文本函数比如fprintf来操作,而使用二进制打开的文件就 ...