hdu 5159 Card (期望)
[Technique specification] All numbers are integers. 1<=T<=500000 1<=x<=100000 1<=b<=5
2 3
3 3
Case #2: 4.222
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
桌子上有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 (期望)的更多相关文章
- HDU 5159 Card (概率求期望)
B - Card Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 5159 Card( 计数 期望 )
Card Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 5159 Card
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- hdu 4336 Card Collector(期望 dp 状态压缩)
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...
- HDU 4336 Card Collector:期望dp + 状压
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...
- HDU 4336 Card Collector:状压 + 期望dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...
- hdu 4336 Card Collector (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- (原)Apache添加完限速模块后的文件
点我下载 解压后得到apache2文件夹和readme.txt文本 按照readme.txt修改apache2文件夹.
- [Typescript] Function defination
Define a function type and params type: // The function init // Accept two params which are both typ ...
- BitmapFactory 加载图片到内存
Bitmap占用内存分析 Android的虚拟机是基于寄存器的Dalvik,它的最大堆(单个进程可用内存)大小一般是16M,当然不同设备是不一样的,可以查看/system/build.prop文件,[ ...
- Redis配置不当可导致服务器被控制,已有多个网站受到影响 #通用程序安全预警#
文章出自:http://news.wooyun.org/6e6c384f2f613661377257644b346c6f75446f4c77413d3d 符合预警中“Redis服务配置不当”条件的服务 ...
- position:fixed定位时 “高度坍塌” 问题的解决
问题:对于固定定位的元素,固定住高度,后面紧跟的模块会当做前面的固定元素不存在似的,这给布局带来了困扰 解决方法: 1.给第二个模块div设置margin-top的值,margin-top的值设为大于 ...
- SpringMVC学习简单HelloWorld实例
首先还是从一个简单的Hello World项目说起: 我机器的开发环境为: Ubuntu12.04(不同操作系统对本系列项目没有影响): 开发工具:Eclipse For JavaEE: 数据库:My ...
- oracle服务开机自启动
1.修改oracle系统配置文件::/etc/oratab vi /etc/oratab orcl:/opt/oracle/product/10.2.0/db_1:Y 2.在 /etc/init.d/ ...
- edit编辑框相关
从Edit Control获取值,然后通过MessageBox输出出来 void CNowaMagic_MFCDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代 ...
- Qt小程序仿写----FileRead程序
该程序实现如下功能:1.打开TXT文件A.txt:2.将文件路径显示到一个文本编辑框里面,文件内容显示到一个文本域里面:3.在文本域里面更改文件内容之后,保存文本域的内容到当前文件路径下. 定义了一F ...
- POJ 1151 - Atlantis 线段树+扫描线..
离散化: 将所有的x轴坐标存在一个数组里..排序.当进入一条线段时..通过二分的方式确定其左右点对应的离散值... 扫描线..可以看成一根平行于x轴的直线..至y=0开始往上扫..直到扫出最后一条平行 ...