DZY Loves Balls

 Accepts: 659
 Submissions: 1393
 Time Limit: 4000/2000 MS (Java/Others)
 Memory Limit: 262144/262144 K (Java/Others)
问题描述
DZY喜欢玩球。

他有nn个球,装进一个大盒子里。每个球上面都写着一个整数。

有一天他打算从盒子中挑两个球出来。他先均匀随机地从盒子中挑出一个球,记为AA。他不把AA放回盒子,然后再从盒子中均匀随机地挑出一个球,记为BB。

如果AA上的数字严格大于BB上的数字,那么他就会感到愉悦。

现在告诉你每个球上的数字,请你求出他感到愉悦的概率是多少。
输入描述
第一行tt,表示有tt组数据。

接下来tt组数据。每组数据中,第一行包含一个整数nn,第二行包含nn个用空格隔开的正整数a_ia​i​​,表示球上的数字。

(1\le t\le 300, 2\le n \le 300,1\le a_i \le 3001≤t≤300,2≤n≤300,1≤a​i​​≤300)
输出描述
对于每个数据,输出一个实数答案,保留6位小数。
输入样例
2
3
1 2 3
3
100 100 100
输出样例
0.500000
0.000000

思路:

对于每个数a[i]求满足条件的个数(即所有数中比a[i]小的个数),然后用它们的和除以总的可能数即可。

include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define LL(x) (x<<1)
#define RR(x) (x<<1|1) const int MOD = 1e9 + 7;
const int maxn = 305;
int n;
int s[maxn];
int a[maxn];
int lowbit(int x)
{
return x&(-x);
} void add(int pos,int x)
{
while(pos <= 300)
{
s[pos] += x;
pos += lowbit(pos);
}
} int sum(int x)
{
int cnt= 0 ;
while(x)
{
cnt += s[x];
x -= lowbit(x);
}
return cnt;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(s,0,sizeof(s));
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
add(a[i],1);
} int all = 0;
int num = n*(n-1);
for(int i = 1;i <= n;i++)
{
all += sum(a[i]-1);
}
printf("%.6f\n",all*1.0/num);
}
return 0;
}

  

hdu 5645 DZY Loves Balls的更多相关文章

  1. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  2. HDU 5194 DZY Loves Balls

    DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. hdu5194 DZY Loves Balls 【概率论 or 搜索】

    //yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的. hdu5194 DZY Loves Balls [概率论 or 搜索] 题意: 一个盒子里有n个黑球和m ...

  4. HDU 5646 DZY Loves Partition

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

  5. HDU 5646 DZY Loves Partition 数学 二分

    DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...

  6. hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  7. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  8. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  9. 数据结构(线段树):HDU 5649 DZY Loves Sorting

    DZY Loves Sorting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

随机推荐

  1. Basys3在线调试视频指南及代码

    fpga在线调试视频链接 FPGA选择型号:xc7a35tcpg236-1 des文件 `timescale 1ns / 1ps module top( output [1:0] led, outpu ...

  2. django报错Manager isn't accessible via UserInfo instances

    出现这种错误是因为调用模型对象时使用了变量名,而不是对象名(模型类),例如: user = UserInfo()user_li = user.objects.filter(uname=username ...

  3. LeetCode & Q169-Majority Element-Easy

    Array Divide and Conquer Bit Manipulation Description: Given an array of size n, find the majority e ...

  4. groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

    参考链接:http://www.cnblogs.com/rightmin/p/4945797.html 1.引入groovy的jar包 2.引入groovy编译插件 3.遇到问题 Plugin exe ...

  5. 新概念英语(1-47)A cup of coffee

    新概念英语(1-47)A cup of coffee How does Ann like her coffee? A:Do you like coffee, Ann? B:Yes, I do. A:D ...

  6. Spring入门(3-1)Spring的标签命名空间

    1.标签命名空间声明: 2.标签命名空间使用 标签默认的命名空间是 security:,可以不用带 security:,直接写标签,如: <http  <authentication-ma ...

  7. Spring之AOP编程

    一.AOP简介     AOP的英文全称是Aspect Oriented Programming,意为:面向切面编程.     AOP采取横向抽取的机制,取代了传统纵向继承体系的代码复用.AOP常用于 ...

  8. python——函数

    python--函数 1.介绍: 在过去的十年间,大家广为熟知的编程方法无非两种:面向对象和面向过程,其实,无论哪种,都是一种编程的规范或者是如何编程的方法论.而如今,一种更为古老的编程方式:函数式编 ...

  9. Spring Cloud之——Config(配置中心)

    Spring Cloud Config(配置中心) 大家好,有一段时间没有写技术博客了.由于工作上的事情,这方面很难分配时间.近几年随着服务化的兴起,一批服务化的框架应运而生,像dubbo,thrif ...

  10. POJ1017 Packets---贪心

    题目链接: https://vjudge.net/problem/POJ-1017 题目大意: 公司共有底面面积为1*1.2*2.3*3.4*4.5*5.6*6,高度同为H的六种产品,现在需要用最少的 ...