SGU 495 Kids and Prizes 概率 二项分布

题目大意:

就是想在有N个奖品分别装在N个盒子里,M个人依次选择盒子,每个人选择每个盒子的可能性都是相等的,当一个人选择盒子之后那个盒子里的奖品就被领走,空盒子放回原位,如果选择了空盒子则没有奖品, 盒子依旧放回原位,问最终送出的奖品的份数的期望


大致思路:

首先对于任何一个盒子,其中的礼物在M个人选择之后依旧没有被拿走的概率是(1 - 1/N)^M, 那么被拿走的可能性是(1 - (1 - 1/N)^M), 由于N个盒子中的奖品是否被拿走了事相互独立的, 一共N个盒子,被拿走礼物的盒子的个数X服从二项分布 X~B(N, (1 - (1 - 1/N)^M)), 故E(X) = N*(1 - (1- 1/N)^M)


代码如下:

Result  :  Accepted     Memory  :  54 KB     Time  :  15 ms

/*
 * Author: Gatevin
 * Created Time:  2014/12/22 15:38:06
 * File Name: Sora_Kasugano.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

int main()
{
    int n,m;
    scanf("%d %d", &n, &m);
    printf("%.9f", n*(1 - pow(1 - 1.0/n, m)));
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值