495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495
学习:当一条路走不通,换一种对象考虑,还有考虑对立面。
495. Kids and Prizes
Memory limit: 262144 kilobytes
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).
The first and only line of the input file contains the values of N and M ().
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.
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的更多相关文章
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- SGU 495. Kids and Prizes( 数学期望 )
题意: N个礼品箱, 每个礼品箱内的礼品只有第一个抽到的人能拿到. M个小孩每个人依次随机抽取一个, 求送出礼品数量的期望值. 1 ≤ N, M ≤ 100, 000 挺水的说..设f(x)表示前x ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...
- Kids and Prizes(SGU 495)
495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: standa ...
- [SGU495] Kids and Prizes (概率dp)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题目大意:有N个盒子,里面都放着礼物,M个人依次去选择盒子,每人仅能选一次,如 ...
- SGU-495 Kids and Prizes 概率DP
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:有n个盒子,每个盒子里面放了一个奖品,m个人轮流去选择盒子,如果盒子里面 ...
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
随机推荐
- 前后端分离--构建前端Mock Server--windows部署rap
mock:模拟的,虚假的 mock server:模拟服务,模拟请求,模拟虚假数据 为了前后端更好的分工,接口文档是必须的,前后端都根据接口文档写代码,然后对接接口就行了. 但是,后端跟不上前端节奏, ...
- Handler 原理分析和使用之HandlerThread
前面已经提到过Handler的原理以及Handler的三种用法.这里做一个非常简单的一个总结: Handler 是跨线程的Message处理.负责把Message推送到MessageQueue和处理. ...
- SQL函数大全(字符串函数).
SQL Server 2005 函数大全 字符串函数 字符串函数 SubString在SQL和C#中不同, 一,select substring('abcde',-1,3) select LEN( ...
- andriod 中设置sdk升级代理服务器
Android SDK 在线更新镜像服务器资源: 大连东软信息学院镜像服务器地址: http://mirrors.neusoft.edu.cn 端口:80 北京化工大学镜像服务器地址: IPv4: h ...
- Object-C 类实现
这篇为Object-C添加方法的后续. 这里我们应该在类的实现(.m)文件中写 #import "Photo.h" @implementation Photo - (NSStrin ...
- C# 之【获取网页】
C#获取指定网页HTML原代码可使用 WebClient WebRequest HttpWebRequest 三种方式来实现. 当然也可使用webBrowse!在此就不研究webBrowse如何获取了 ...
- struts2 测试错题解析
解析:$.parseJSON()方法是将字符串转换成Json类型数据,$.getJSON()方法是获取JSON数据,两者不用联合使用. 解析: A:ActionContext接口没有getReques ...
- Windows Phone 之播放视频
在Windows Phone 7中播放视频有两种方式, (1)使用MediaElement 控件来播放:用MediaElement 控件来播放视频比较灵活,你需要自己去实现播放暂停进度条等等的功能,播 ...
- [转] js call
call 方法 转自: http://www.cnblogs.com/sweting/archive/2009/12/21/1629204.html调用一个对象的一个方法,以另一个对象替换当前对象. ...
- CSS中:nth-child和JQuery:eq的区别
$("li:nth-child(n)")选择器与$("li:eq(n)")选择器的不同之处在于:$("li:eq(n)")选择器只匹配一个元 ...