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 ...
随机推荐
- win10-idea2018
下载jar JetbrainsCrack-2.9-release-enc.jar idea64.exe.vmpotions 配置 -javaagent:D:\devsoft\idea\bin\Jetb ...
- [LeetCode] Intersection of Two Linked Lists 两链表是否相交
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 【Python学习】字符编码
先说两个基础知识. (1)计算机内部,数据是由0,1组成的: (2)计算机最小的数据单位,就是一个二进制单位即bit,接下来就是8个二进制单位表示一个字节(Byte). 1 ASCII码 ASCII码 ...
- Linux kernel学习-内存管理
转自:https://zohead.com/archives/linux-kernel-learning-memory-management/ 本文同步自(如浏览不正常请点击跳转):https://z ...
- shell编程===执行shell脚本的四种方法
使用vim创建一个shell文件,命名 hello.sh #!/bin/bash echo "hello shell !" 在linux中进行加载 chmod +x ./hello ...
- Spring源码解读Spring IOC原理
一.什么是Ioc/DI? IoC 容器:最主要是完成了完成对象的创建和依赖的管理注入等等. 先从我们自己设计这样一个视角来考虑: 所谓控制反转,就是把原先我们代码里面需要实现的对象创建.依赖的代码,反 ...
- Vue进阶篇
前引 今天是2018年12月30,虽不是2018年的最后一天,但是却是自己在2018年写的最后一篇博客了,昨天下班在地铁上闲来无事,翻起了关注的一些公众号发的技术博文,里面就提到写博客的重要性,其实这 ...
- 专题-Delphi/C++ Builder多线程编程与调试
[目录] Delphi.C++ Builder多线程程序编码调试的一点经验谈 多线程程序的填坑笔记和多线程编程应该遵循的规则(天地弦) 多线程编程中死锁问题的跟踪与解决 临界.多重读独占写多线程同步测 ...
- LoadRunner中InvokeMethod failure: 外部组件发生异常解决办法
-82801 abnormal termination,caused by mdrv process termination -29996 error:process mmdrv.exe was no ...
- JS获取select的value和text值的简单实例
本篇文章主要是对JS获取select的value和text值的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <select id = "cityList ...