题意: N个礼品箱, 每个礼品箱内的礼品只有第一个抽到的人能拿到. M个小孩每个人依次随机抽取一个,  求送出礼品数量的期望值. 1 ≤ N, M ≤ 100, 000

挺水的说..设f(x)表示前x个人都选择完成后礼品剩下数的期望值( f(0) = N ), 那么f(x) = f(x - 1) - f(x - 1) / N = f(x - 1) * (N - 1) / N (显然). 那么答案就是等于 N - N * [(N - 1) / N]^M. 后面部分可以用快速幂优化.时间复杂度O(log M). 数据这么小不用快速幂O(M)应该也能过...

-----------------------------------------------------------------------------

#include<bits/stdc++.h>
 
using namespace std;
 
double POW(double p, int a) {
double ans = 1;
for(; a; a >>= 1) {
if(a & 1) ans *= p;
p *= p;
}
return ans;
}
 
int main() {
int N, M;
scanf("%d%d", &N, &M);
printf("%.9lf\n", N - POW(1.0 * (N - 1) / N, M) * N);
return 0;
}

-----------------------------------------------------------------------------

495. Kids and Prizes

Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the company organized a contest for kids for the best design of a cardboard box and selected M winners. There are N prizes for the winners, each one carefully packed in a cardboard box (made by the ICPC, of course). The awarding process will be as follows:

  • All the boxes with prizes will be stored in a separate room.
  • The winners will enter the room, one at a time.
  • Each winner selects one of the boxes.
  • The selected box is opened by a representative of the organizing committee.
  • If the box contains a prize, the winner takes it.
  • If the box is empty (because the same box has already been selected by one or more previous winners), the winner will instead get a certificate printed on a sheet of excellent cardboard (made by ICPC, of course).
  • Whether there is a prize or not, the box is re-sealed and returned to the room.

The management of the company would like to know how many prizes will be given by the above process. It is assumed that each winner picks a box at random and that all boxes are equally likely to be picked. Compute the mathematical expectation of the number of prizes given (the certificates are not counted as prizes, of course).

Input

The first and only line of the input file contains the values of N and M ().

Output

The first and only line of the output file should contain a single real number: the expected number of prizes given out. The answer is accepted as correct if either the absolute or the relative error is less than or equal to 10-9.

Example(s)
sample input
sample output
5 7 
3.951424 

sample input
sample output
4 3 
2.3125 

SGU 495. Kids and Prizes( 数学期望 )的更多相关文章

  1. SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...

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

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

  3. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  4. 495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 学习:当一条路走不通,换一种对象考虑,还有考虑对立面. 495. Kids and Pr ...

  5. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  6. SGU495Kids and Prizes 数学期望

    题意: 有n个奖品,m个人排队来选礼物,对于每个人,他打开的盒子,可能有礼物,也有可能已经被之前的人取走了,然后把盒子放回原处.为最后m个人取走礼物的期望. 题解: 本道题与之前的一些期望 DP 题目 ...

  7. Kids and Prizes(SGU 495)

    495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: standa ...

  8. SGU495Kids and Prizes(数学期望||概率DP||公式)

    495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...

  9. [SGU495] Kids and Prizes (概率dp)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题目大意:有N个盒子,里面都放着礼物,M个人依次去选择盒子,每人仅能选一次,如 ...

随机推荐

  1. jQ 操作积累

    1.判断radio是否选中:方式一:var val=$('input:radio[name="sex"]:checked').val(); //(val==null 未选中) 方式 ...

  2. C#语言基础之运算符

    运算符分类.优先级 运算符:一.数学运算符:+,-,*,/,++,-- 示例1: 示例2: 示例3: 1.递增运算符:++(1)前缀递增运算符    int x=4;    x++;//输出结果,x的 ...

  3. Redis初始化配置及增删改查

    package com.calc.tools import redis.clients.jedis.JedisPool import redis.clients.jedis.Jedis import ...

  4. CocoaPods对于不同Target引入不同的第三方库Podfile的写法

    有的时候我们需要建立多个Target来完成不同的测试环境的区分,而多个Target之间可能会有第三方库的不同引用,如果我们在使用CocoaPods管理我们的第三方库的时候,我们就需要思考我们需要如何实 ...

  5. 获得view所在的控制器

    - (UIViewController*)getViewController{ for (UIView* next = [self superview]; next; next = next.supe ...

  6. Android目录结构介绍&Android学习之hello world

    分类: 嵌入式 一个android项目有如下目录: src:这里放的是我们编写的源代码 gen:这里的是eclipse自动生成的文件,不用管它 asssts:放置文件 res:也是放置文件,不同的是r ...

  7. mysql 添加用户并授权(记录)

    mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY 'something' WITH GRANT OPTION ...

  8. [Git]自译《Git版本控制管理》——1.介绍(二)_Git诞生

    译者前言:      本系列译文为作者利用业余时间翻译,有些疏漏与翻译不到位的地方敬请谅解.      不过也很希望各位读者能给出中肯的建议.      方括号的注释,如[1][2]为译者注.     ...

  9. LINUX下使用crontab进行RMAN备份实验

    之前写了脚本,手动执行可以,使用crontab总是无法运行成功,今天下午花了两个小时实验,完成如下: 注意事项:脚本完成首先手动执行,确定可以正常执行. 在crontab中使用,要注意以下几点: 1. ...

  10. 链接分析算法之:SALSA算法

    链接分析算法之:SALSA算法 SALSA算法的初衷希望能够结合PageRank和HITS算法两者的主要特点,既可以利用HITS算法与查询相关的特点,也可以采纳PageRank的“随机游走模型”,这是 ...