DZY Loves Balls
2016-03-19 20:45
302 查看
DZYLovesBalls
Accepts:662Submissions:1392TimeLimit:4000/2000MS(Java/Others)MemoryLimit:262144/262144K(Java/Others)ProblemDescriptionDZYlovesplayingballs.Hehasnnnballsinabigbox.Oneachballthereisanintegerwritten.Onedayhedecidestopicktwoballsfromthebox.Firstherandomlypicksaballfromthebox,andnamesitAAA.Next,withoutputtingAAAbackintothebox,herandomlypicksanotherballfromthebox,andnamesitBBB.IfthenumberwrittenonAAAisstrictlygreaterthanthenumberonBBB,hewillfeelhappy.Nowyouaregiventhenumbersoneachball.Pleasecalculatetheprobabilitythathefeelshappy.InputFirstlinecontainstttdenotingthenumberoftestcases.ttttestcasesfollow.Ineachtestcase,firstlinecontainsnnn,secondlinecontainsnnnspace-separatedpositiveintegersaia_iai,denotingthenumbersontheballs.(1≤t≤300,2≤n≤300,1≤ai≤3001\let\le300,2\len\le300,1\lea_i\le3001≤t≤300,2≤n≤300,1≤ai≤300)OutputForeachtestcase,outputarealnumberwith6decimalplaces.SampleInputCopy231233100100100SampleOutputCopy
0.500000 0.000000
#include<stdio.h>#include<algorithm>usingnamespacestd;inta[1000];intmain(){intt,n,i,j;doubleb;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}doublep;p=n*(n-1);sort(a,a+n);doublesum=0;for(i=n-1;i>=0;i--){for(j=i-1;j>=0;j--){if(a[i]>a[j]){sum=sum+1;}}}b=sum/p;printf("%.6lf\n",b);}}
相关文章推荐
- 使用注解来折腾BaseAdapter(1)
- GDB之coredump的学习
- 【一周读书】年轻人你可别哭啊
- 优化MySchool总结习题
- eclipse 添加resources 目录
- Linux ./configure --prefix 命令是什么意思?
- HDOJ-2069 Coin Change(母函数)
- LeetCode108—Convert Sorted Array to Binary Search Tree
- Struts2中jsp前台传值到action后台的三种方式 <转载>属性加载,模型加载
- ffmpeg参数中文详细解释
- java中的常用类、Date和SimpleDateFormat类表示时间、java中基本类型和包装之间的转换
- 第四周项目5递归求阶乘
- 记codeforces两题
- Hibernate逍遥游记-第2章-使用hibernate.properties
- debian ubuntu linux系好用的包管理工具 aptitude
- 输入一个多项式F(X) 计算出(F(X))^P
- 简单谈谈C++中的引用与指针
- 关于surf显示立体图,可视化分析数据
- 初识NuGet - 概念, 安装和使用
- jdk环境变量配置