题目链接:

DZY Loves Balls

Time Limit: 4000/2000 MS (Java/Others)   

 Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 105    Accepted Submission(s): 75

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
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[600];
int main()
{int t,n,k;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&a[i]);}double ans=0;for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(i!=j){if(a[j]<a[i])ans+=1/(n*(n-1)*1.0);}}}printf("%.6lf\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/zhangchengc919/p/5296602.html

hdu-5645 DZY Loves Balls(水题)相关推荐

  1. HDU 5646 DZY Loves Partition

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5646 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  2. HDU 6264 Super-palindrome(CCPC2017杭州) 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=6264 题目大意:给定字符串TTT,使得该字符串的每个长度为奇数的子串都是回文串,求至少要修改的字符的数量. 思路 ...

  3. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  4. 【HDU - 5585】Numbers (水题,数学,数论)

    题干: There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise ...

  5. HDU 2549 壮志难酬 (水题,但有个小坑!)

    壮志难酬 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...

  7. HDU 5112 A Curious Matt 水题

    A Curious Matt Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  8. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题

    A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...

  9. HDU 5680 zxa and set 水题

    zxa and set 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4681 Description zxa has a set A={a1,a2, ...

最新文章

  1. 对联广告,带关闭,可以移动
  2. Python学习的十个阶段,学完大成,对应一下看看你自己在哪个阶段
  3. 清华张悠慧:AI时代,「图灵完备」之后,「类脑计算完备」如何设计?
  4. Oracle 10g安装64位图解流程
  5. WPF and Silverlight 学习笔记(九):WPF布局管理之Canvas、InkCanvas
  6. IOS中http请求使用cookie
  7. CCNA考试的一点体会
  8. Explain:解决MUI 软键盘弹起挤压页面问题
  9. phpstorm破解安装
  10. sql的子查询超级慢-子查询酿的祸
  11. c语言设计第4章答案,《C语言程序设计》第4章习题答案.doc
  12. GoF的23种设计模式之创建型模式的特点和分类
  13. “找不到网络路径”的检测方法及解决方案
  14. poj 3897 Maze Stretching 二分+A*搜索
  15. [JSOI2010] 连通数
  16. linux不显示无线网卡驱动安装失败,无线网卡在Linux下安装
  17. AntColony 磁力搜索BT引擎的核心
  18. 苹果笔记本开机出现闪烁的问号文件夹解决方法
  19. 海马苹果助手ipad版_苹果IPA文件签名,软件掉签问题,自己也能轻松解决
  20. 【Spark Core】【RDD】【01】核心属性 执行原理

热门文章

  1. mysql5.7.1 zip版本安装记录
  2. CACTI 仙人掌监控平台
  3. 己椒苈黄汤治水肿案(联想的风)
  4. https传输基于多ip实现的网站数据传输
  5. 苹果发布新应用Find My Friends,轻松追踪朋友和家人的所在位置
  6. 小组文化——洗洗睡了的故事
  7. Altlas M1 and Tips of Debugger Visualizers
  8. C中的预编译宏定义-转
  9. IOC 容器中那些鲜为人知的细节(关于 autowiring)
  10. 1052. 卖个萌 (20)-PAT乙级真题