Problem Description
There are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b rounds. Assume that the score of the j-th card he picks is Sj . You are expected to calculate the expectation of the sum of the different score he picks.
 
Input
Multi test cases,the first line of the input is a number T which indicates the number of test cases.  In the next T lines, every line contain x,b separated by exactly one space.
[Technique specification] All numbers are integers. 1<=T<=500000 1<=x<=100000 1<=b<=5
 
Output
Each case occupies one line. The output format is Case #id: ans, here id is the data number which starts from 1,ans is the expectation, accurate to 3 decimal places. See the sample for more details.
 
Sample Input
2
2 3
3 3
 
Sample Output
Case #1: 2.625
Case #2: 4.222

Hint

For the first case, all possible combinations BieBie can pick are (1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2)
For (1,1,1),there is only one kind number i.e. 1, so the sum of different score is 1.
However, for (1,2,1), there are two kind numbers i.e. 1 and 2, so the sum of different score is 1+2=3.
So the sums of different score to corresponding combination are 1,3,3,3,3,3,3,2
So the expectation is (1+3+3+3+3+3+3+2)/8=2.625

 
Source
 
题意:

桌子上有a张牌,每张牌从1到a编号,编号为i(1<=i<=a)的牌上面标记着分数i , 每次从这a张牌中随机抽出一张牌,然后放回,执行b次操作,记第j次取出的牌上面分数是 Sj, 问b次操作后不同种类分数之和的期望是多少。
思路:

设Xi代表分数为i的牌在b次操作中是否被选到,Xi=1为选到,Xi=0为未选到
那么期望EX=1*X1+2*X2+3*X3+…+x*Xx
Xi在b次中被选到的概率是1-(1-1/x)^b
那么E(Xi)= 1-(1-1/x)^b
那么EX=1*E(X1)+2*E(X2)+3*E(X3)+…+x*E(Xx)=(1+x)*x/2*(1-(1-1/x)^b)
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
double x,b;
int ac=;
while(t--)
{
scanf("%lf%lf",&x,&b);
double ans=;
double p=-pow((-1.0/x),b);
double num=(+x)*x*1.0/;
ans=num*p;
printf("Case #%d: ",++ac);
printf("%.3lf\n",ans);
}
return ;
}
 

hdu 5159 Card (期望)的更多相关文章

  1. HDU 5159 Card (概率求期望)

    B - Card Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  2. HDU 5159 Card( 计数 期望 )

    Card Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. HDU 5159 Card

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...

  4. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  5. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  6. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  7. HDU 4336 Card Collector:期望dp + 状压

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...

  8. HDU 4336 Card Collector:状压 + 期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...

  9. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. mysql简单练习

    数据库入门 2.1 引入 数据保存到内存: 优点: 1)读写非常快 缺点: 1)程序关闭导致数据丢失 数据保存到文件: 优点: 1)数据可以永久保存 缺点: 1)频繁地IO操作,效率不高! 2)数据管 ...

  2. Android实现获取本机中所有图片

    本示例演示如何在Android中使用加载器(Loader)来实现获取本机中的所有图片,并进行查看图片的效果. 在这个示例中,我使用android-support-v4.jar中的加载器(Loader) ...

  3. C#、.NET和ASP.NET三者之间的区别

    刚毕业后出去找工作面试的时候就遇到这个问题!.回答不上来.回来网上查的如下: 那么 .NET.C#和ASP.NET这三者之间区别不清楚,到底它们之间有什么联系呢? 1..NET是一个平台,一个抽象的平 ...

  4. 【回顾整理】HTML+CSS个的两个实战项目

    一:麦子商城首页制作 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset= ...

  5. NHibernate之映射文件配置说明(转载3)

    十二.组件(component), 动态组件(dynamic-component) <component>元素把子对象的一些元素与父类对应的表的一些字段映射起来. 然后组件可以定义它们自己 ...

  6. scala学习笔记——类和对象

    基础语法关于Scala程序,这是非常要注意以下几点. 区分大小写 - Scala是大小写敏感的,这意味着标识Hello 和 hello在Scala中会有不同的含义. 类名 - 对于所有的类名的第一个字 ...

  7. php+js 瀑布流源码

    官方网站:更多源码 新浪微博:QQ公众号 QQ:各种源码 602902342 大牛技术群: 452207697 下载地址:http://pan.baidu.com/s/1bnNipI3 密码: h93 ...

  8. C#进程与线程

    public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { / ...

  9. C++中的析构函数

    代码: #include <cstdio> #include <iostream> using namespace std; class A{ public: ~A(){ co ...

  10. 2016年最受欢迎中国开源软件TOP 20

    开源软件对程序员来说是一个经常接触的软件,作为一个经常接触的软件,当然想知道自己用的软件受欢迎程度,基于此,开源中国在近日公布“2016年度最受欢迎中国开源软件评选”结果,在TOP20榜单中,前5名分 ...