http://acm.sgu.ru/problem.php?contest=0&problem=495

学习:当一条路走不通,换一种对象考虑,还有考虑对立面。

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

题意:n个盒子里装有礼物,m个人随机选择礼物,选完之后空盒子放回
问选中的礼物数的期望。

m个人是独立的。
对于每个礼物不被人选中的概率为((n-1)/n)^m
那么不被选中的礼物数的期望就是 n*((n-1)/n)^m
所以答案就是 n-n*((n-1)/n)^m;

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,m;
double pow(double x,int y)
{
int i;
double sum=;
for(i=;i<=y;i++)
sum*=x;
return sum;
}
int main()
{
double cnt;
double ans;
while(~scanf("%d%d",&n,&m))
{
cnt=double(n-)/n;
ans=n-n*pow(cnt,m);
printf("%.9lf\n",ans);
}
return ;
}

495. Kids and Prizes的更多相关文章

  1. SGU 495. Kids and Prizes

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

  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( 数学期望 )

    题意: N个礼品箱, 每个礼品箱内的礼品只有第一个抽到的人能拿到. M个小孩每个人依次随机抽取一个,  求送出礼品数量的期望值. 1 ≤ N, M ≤ 100, 000 挺水的说..设f(x)表示前x ...

  4. 【SGU】495. Kids and Prizes

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

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

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

  6. Kids and Prizes(SGU 495)

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

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

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

  8. SGU-495 Kids and Prizes 概率DP

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:有n个盒子,每个盒子里面放了一个奖品,m个人轮流去选择盒子,如果盒子里面 ...

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

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

随机推荐

  1. latch: cache buffers chains故障处理总结

    一大早就接到开发商的电话,说数据库的CPU使用率为100%,应用相应迟缓.急匆匆的赶到现场发现进行了基本的检查后发现是latch: cache buffers chains 作祟,处理过程还算顺利,当 ...

  2. GET请求和POST请求

    A:有哪些get请求呢? a.在浏览器地址栏直接输入一个请求地址 b.点击超链接 c.表单默认的提交方式method="GET/get" B:get请求方式的特点 a.会将请求参数 ...

  3. 如何生成publish windows app 用到的 pfx 文件

    参考文章 https://msdn.microsoft.com/en-us/library/windows/desktop/jj835832(v=vs.85).aspx 1.在项目中查找.appxma ...

  4. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  5. C语言带参数的main函数

    C语言带参数的main函数 #include<stdio.h> int main(int argc,char*argv[]) { int i; ;i<argc;i++) printf ...

  6. 一段C++代码想到的问题

    今天在学习<Unix环境高级编程>,第七章进程环境给出了一个进程的内存分布示意图,从下往上依次为“正文段->初始化数据->未初始化数据(默认初始化为0)->堆(从低地址到 ...

  7. Bresenham画直线,任意斜率

    function DrawLineBresenham(x1,y1,x2,y2) %sort by x,sure x1<x2. if x1>x2 tmp=x1; x1=x2; x2=tmp; ...

  8. 速卖通---发布商品aeopAeProductPropertys这个字段值报07004013的错误

    由于文档的说明很少,导致里面改填写那些值都是靠自己推敲出来,当然可以根据他们的错误提示了研究,他们的错误提示也给出了相关的帮助了, 例如通过categoryid的200000001获取到"i ...

  9. mongo数据库使用小结

    db.userId5555.aggregate({$unwind:"$tcjl"},{$match:{"_id":"0e549864-2a56-43c ...

  10. jQuery 标签淡入淡出 个人随笔

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...