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