HDU 5159 Card (概率求期望)
Description
Input
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
See the sample for more details.
Sample Input
2 3
3 3
Sample Output
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.62
题意:x张牌,每张牌的值从1到x。依次取b张,注意不是一次性取,即取12和取21是两种情况。问所取的牌中值不同的牌的总和的期望为多少。输入一组数据t,然后t行,每行一个x一个b。Hint给出了第一个样例的解释,看了就能懂。
题解:首先x张牌依次取b张,因为每一次取都有x种情况,所以一共会出现x^b种情况,那么如果x-1张牌取b张牌就会出现(x-1)^b种情况,所以一张牌会有x^b-(x-1)^b种情况,就是指有这么多种情况包含这张牌,而且对于每张牌都是这样的。那么这张牌出现的概率为(x^b-(x-1)^b)/x^b。由概率求期望的公式可知,这张牌的期望为这张牌的值乘以这张牌出现的概率。那么总期望就为所有牌的值的和乘以牌出现的概率,因为每张牌出现的概率是相同的,所有牌的值的和为x*(x+1)/2,将每张牌的概率的公式化简可得1-((1-1/x)^b),相乘即可,得出最终公式(1-pow(1-1.0/x,b))*x*(x+1)/2。
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
int t,cas=;
double x,b;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x,&b);
printf("Case #%d: %.3lf\n",cas++,(-pow(-1.0/x,b))*x*(x+)/);
}
return ;
}
HDU 5159 Card (概率求期望)的更多相关文章
- HDU 5159 Card( 计数 期望 )
Card Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- HDU 4336 Card Collector:期望dp + 状压
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...
- HDU 5159 Card
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...
- HDU 4336 Card Collector 数学期望(容斥原理)
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...
- HDU 5245 Joyful(概率题求期望)
D - Joyful Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
随机推荐
- 【word】html转doc的小研究
html转doc,页眉页脚丢失 html 转 doc,是全屏铺满(缩放级别很高)
- linux-shell——01
没有什么好的标题,只是一些随笔.我用的是linux虚拟机,red hat 7 一:nat模式使得虚拟机可以访问外网,但是这种模式下只可以访问外网,但外面的不能访问里面 首先将虚拟机的网络连接改为nat ...
- Postgres常用命令之增、删、改、查
增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...
- 34-Cookie-based认证实现
新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController.cs u ...
- TouTiao开源项目 分析笔记19 问答内容
1.真实页面预览 1.1.成果预览 首先是问答列表 然后每个item设置点击事件,进入问答内容列表 然后每一个问答内容也设置点击事件,进入问答详情 1.2.触发事件. 在WendaArticleOne ...
- PHP.19-验证码生成
生成验证码 思路:先定义验证码函数getCode() //绘制验证码 $num = 4; //字符长度 getCode($num, 2); 1.创建画布,分配颜色 imagecreatetruecol ...
- vue-cli 引入axios
写文章注册登录 首页 下载App × vue-cli 引入axios及跨域使用 星球小霸王 关注 2017.10.04 16:40* 字数 504 阅读 13038评论 2喜欢 18 使用 c ...
- 《1024伐木累-周末特别篇》-中彩票了,开发APP
本周发布的<1024伐木累>,受到了很多码汪们的好评,博主在这里感谢大家的支持,同时,博主临时起意,增加一期周末对话特别篇,让大家在“满血复活”的时间里,充分感受快乐的味道~ 1.中彩票 ...
- C# p-Inovke C++动态链接库
在C++的动态链接库 写了一个测试方法,然后想在C#客户端进行pInvoke调用,始终报异常如下: 试图加载格式不正确的程序. (异常来自 HRESULT:0x8007000B). 最后发现, 需要将 ...
- linux统计分析流量-wireshark
wireshark是一款带界面的开源抓包工具,可以用来对系统流量进行统计分析. 安装 由于wireshark是带界面的,所以一般在界面环境下运行,可以通过yum安装: $ yum install -y ...