HDU 5645 DZY Loves Balls 水题
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 水题的更多相关文章
- hdu 5645 DZY Loves Balls
DZY Loves Balls Accepts: 659 Submissions: 1393 Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- HDU 5194 DZY Loves Balls
DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 5268 ZYB loves Score 水题
ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- hdu 5272 Dylans loves numbers 水题
Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- HDU 5655 CA Loves Stick 水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 CA Loves Stick Accepts: 381 Submissions: 3204 ...
- hdu5194 DZY Loves Balls 【概率论 or 搜索】
//yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5590 ZYB's Biology 水题
ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
随机推荐
- koa通过get请求获取参数
1.通过get方式请求获取参数的方式有两种 通过上下文获取 通过request获取 获得的格式有两种:query与querystring 注意:querystring为小写,驼峰格式会导致无法获取 2 ...
- 生产环境手把手部署ERC20智能合约
工具 rimex http://remix.ethereum.org/ metamask https://metamask.io/ ERC20 代码 https://github.com/OpenZe ...
- linux设备驱动模型-浅析-转
1. typeof typeof并非ISO C的关键字,而是gcc对C的一个扩展.typeof是一个关键字(类似sizeof),用于获取一个表达式的类型. 举个简单的例子: char tt; typ ...
- vundle+vim8+php+xdebug
vundle 一开始容易被坑,vundle的运行方法是自己下载,不是自己下载,在安装上vundle后,直接修改~/.vimrc中,Plugin增加插件,然后运行PluginInstall即可安装 vi ...
- puppet overview
安装 以在Ubuntu server 14.04.2 TLS 为例: 设置机器名. 编辑/etc/host以修改主机名,因为puppet是基于证书的,证书中包含主机名: 更新包源. echo -e & ...
- Geoserver WFS跨域设置
测试版本为geoserver2.11.0. 两种方法都可以实现跨域设置: 第一种: 下载跨域jar包jetty-servlets.jar(下载geoserver使用的对应jetty版本——可以查看&l ...
- caffe源码整个训练过程
Caffe源码 Blob protected: shared_ptr<SyncedMemory> data_; shared_ptr<SyncedMemory> diff_; ...
- Photon3Unity3D.dll 解析二——EventData
EventData 包含Photon事件的所有内容 Code 用于表示事件,相当于主键ID,LiteEventCode定义了一部分服务端普遍事件事件: Parameters 事 ...
- Java容器---Collection接口中的共有方法
1.Collection 接口 (1)Collection的超级接口是Iterable (2)Collection常用的子对象有:Map.List.Set.Queue. 右图中实现黑框的ArrayLi ...
- [实战]MVC5+EF6+MySql企业网盘实战(15)——逻辑重构2
写在前面 上篇文章修改文件上传的逻辑,这篇修改下文件下载的逻辑. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) [实 ...