您的位置:首页 > 其它

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_ia​i​​,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≤a​i​​≤300)OutputForeachtestcase,outputarealnumberwith6decimalplaces.SampleInputCopy
231233100100100
SampleOutputCopy
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);}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: