B - Card

Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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 {{\rm{S}}_{\rm{j}}} . 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.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 (概率求期望)的更多相关文章

  1. HDU 5159 Card( 计数 期望 )

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

  2. hdu 5159 Card (期望)

    Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...

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

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

  4. HDU 5159 Card

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

  5. HDU 4336 Card Collector 数学期望(容斥原理)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

  6. HDU 5245 Joyful(概率题求期望)

    D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  7. sgu 495. Kids and Prizes (简单概率dp 正推求期望)

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  8. HDU3853-LOOPS(概率DP求期望)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  9. poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3523   Accepted: 1740 ...

随机推荐

  1. html页面 加载完成后再刷新 一次

    主要用于第一次加载页面有部分加载bug,再刷新一次即可正常运行. 简单粗暴直接上代码,不带参数,0影响 <Script>function refresh(){ url = location ...

  2. PLC状态机编程第四篇-历史状态处理

    今天我们接着上次的控制任务,加入历史状态,这个任务会比较复杂,象这样的任务我们倾向于自动生成PLC程序,自己写容易出错.但为了演示,我们可以尝试一下.言归正传,下面是我们的控制任务. 控制任务 这次的 ...

  3. python学习之字符串转换

    配置环境:python 3.6   python编辑器:pycharm 代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- def strCase() ...

  4. POJ 1180 斜率优化DP(单调队列)

    Batch Scheduling Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4347   Accepted: 1992 ...

  5. POJ :3614-Sunscreen

    传送门:http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...

  6. Numpy数据存取与函数

    数据的CSV文件存取 多维数据的存取 NumPy的随机数函数 NumPy的统计函数 NumPy的梯度函数

  7. Flume是什么

    分布式流式实时收集日志文件系统,便于实时在线的流式计算,常配合 Storm 和 spark streming 使用. Flume is a distributed分布式的, reliable可靠的, ...

  8. 十四、pymysql模块

    一.安装的两种方法 第一种 #安装 pip3 install pymysql 第二种 二.链接,执行sql,关闭(游标) import pymysql user= input('用户名:>> ...

  9. NetCore log4net 集成以及配置日志信息不重复显示或者记录

    NetCore log4net 集成,这是一个很常见而且网上大批大批的博文了,我写这个博文主要是为了记录我在使用过程中的一点小收获,以前在使用的过程中一直没有注意但是其实网上说的不清不楚的问题. 官方 ...

  10. Eclipse 创建 Java 包---Eclipse教程第09课

    打开新建 Java 包向导 你可以使用新建 Java 包向导来创建 Java 包.Java 包向导打开方式有: 通过点击 "File" 菜单并选择 New > Package ...