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
 代码:
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i,j,a[9999];
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
double sum;
sum=n*(n-1);
double ans=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]>a[i])
ans++;
}
}
double p;
p=ans/sum;
printf("%.6lf\n",p);
}
return 0;
}

思路:签到水题。


最新文章

  1. sql搜索like通配符的用法详解
  2. 博客迁移到独立域名owenchen.net,此博客不再更新。
  3. C# 获取地址栏的地址(URL)
  4. HTML5新特性之WebRTC
  5. cookie 暂时保存内容与恢复
  6. android 有时候stroke不起作用
  7. Oracle 课程八之性能优化之Oracle SQL Trace
  8. Integer自动装箱分析
  9. ACM2028
  10. python-布尔值
  11. Mac 域名解析
  12. 自己定义android 4.0以上的对话框风格
  13. Xp下麦克风设备及音量检测
  14. Thrift全面介绍
  15. JGUI源码:Tab组件实现(9)
  16. SQL对照LinQ的基本语句
  17. 排序(I)
  18. RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题
  19. cad2020卸载/安装失败/如何彻底卸载清除干净cad2020注册表和文件的方法
  20. vue项目警告There are multiple modules with names that only differ in casing

热门文章

  1. java变量的命名使用规则
  2. Mybatis源码分析之Mapper的创建和获取
  3. asp.net core集成MongoDB
  4. noip历届 &amp;&amp; 打代码常犯错误总结
  5. [转]jquery加载页面的方法(页面加载完成就执行)
  6. python - 在Windows系统中安装Pygame及导入Eclipse
  7. 【原】【Git】EGit强制覆盖本地文件
  8. Petuum - Careers
  9. AskUsingForm_c函数
  10. Spring通过Gmail SMTP服务器MailSender发送电子邮件