HDU 5645
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
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.
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
)
#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的更多相关文章
- HDU 5645 DZY Loves Balls 水题
DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...
- hdu 5645 DZY Loves Balls
DZY Loves Balls Accepts: 659 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- 【WXS数据类型】Function
属性: 名称 值类型 说明 [Function].constructor [String] 返回值为“Function”,表示类型的结构字符串 [Function].length [Number] 返 ...
- 手机端网页返回顶部js代码
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- Memcache的客户端连接系列(二) Python
关键词: Memcached Python 客户端 声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南.客户端连接方法通用,故摘抄过来分享给大家. Python ...
- 【MySQL解惑笔记】忘记MySQL数据库密码
破解MySQL密码 一.MySQL5.7.5之前 只要有系统root密码就可以破解: [root@host- ~]# vim /etc/my.cnf //在配置文件中加入如下内容 [mysqld] s ...
- ubuntu 18.04 LTS server系统安装失败问题解决
准备自己搭一个服务器,USB引导盘的方式安装ubutun系统. 中途遇到两个问题,导致耗时比较久,记录如下. 问题一: installing system阶段卡主 具体描述: 配置镜像源地址以后,进入 ...
- maven 安装、配置
简介: maven 大大提高项目开发速度 编译---打包---测试--安装 一条龙 maven将项目构建的过程标准化,每一个阶段使用一个命令完成,下面是构建过程一些阶段 清理 mvn cl ...
- python常用命令—终端安装win32的两种方法
1, pip install pywin32 2, pip install pypiwin32
- LeetCode 169. Majority Element - majority vote algorithm (Java)
1. 题目描述Description Link: https://leetcode.com/problems/majority-element/description/ Given an array ...
- location 匹配规则 (NGINX)
转:https://moonbingbing.gitbooks.io/openresty-best-practices/ngx/nginx_local_pcre.html location 匹配规则 ...
- C中文件操作的文本模式和二进制模式,到底有啥区别?
在C中,使用fopen打开文件有两种模式:一种是文本模式,一种是二进制模式.那这两种模式之间有什么区别,是不是使用文本模式打开的文件就只能使用文本函数比如fprintf来操作,而使用二进制打开的文件就 ...