SGU 495 Kids and Prizes [期望]
来源:互联网 发布:虚拟现实软件 编辑:程序博客网 时间:2024/05/29 05:12
Description
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.
题意:
有N个箱子里装着礼物,M个人过来挑箱子,每个人是独立的,当一个人选了一个有礼物的箱子,他会拿走礼物,并把空箱子放回去,也就是说下一个人选这个箱子的话会得不到礼物,问最终M个人得到礼物个数的期望。
范围:
N<=10W
解法:
如果从最后会有几个箱子被打开过这一角度来思考,这一题非常难做,至少是N^2的复杂度,所以需要转换思想,计算每个礼物对最后答案的贡献,可知每个人相互独立,那么可以计算得到每个箱子被M个人打开的概率P,然后n*p便是答案(二项分布的期望公式)。
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<iostream>#include<stdlib.h>#include<set>#include<map>#include<queue>#include<vector>#include<bitset>#pragma comment(linker, "/STACK:1024000000,1024000000")template <class T>bool scanff(T &ret){ //Faster Input char c; int sgn; T bit=0.1; if(c=getchar(),c==EOF) return 0; while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); if(c==' '||c=='\n'){ ret*=sgn; return 1; } while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10; ret*=sgn; return 1;}#define inf 1073741823#define llinf 4611686018427387903LL#define PI acos(-1.0)#define lth (th<<1)#define rth (th<<1|1)#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)#define mem(x,val) memset(x,val,sizeof(x))#define mkp(a,b) make_pair(a,b)#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define pb(x) push_back(x)using namespace std;typedef long long ll;typedef pair<int,int> pii;int main(){ int n,m; scanff(n); scanff(m); double p=double(n-1)/double(n); double t=double(n); rep(i,1,m){ t=t*p; } double ans=double(n)-t; printf("%.10f\n",ans); return 0;}
0 0
- SGU 495 Kids and Prizes(期望)
- SGU 495 Kids and Prizes(期望)
- SGU 495 Kids and Prizes [期望]
- [ACM] SGU 495 Kids and Prizes (概率,期望,二项分布)
- SGU 495 Kids and Prizes(期望DP || 数学规律)
- SGU 495 Kids and Prizes (概率期望DP)
- SGU 495. Kids and Prizes 期望
- Kids and Prizes - SGU 495
- SGU 495 Kids and Prizes
- SGU 495 Kids and Prizes
- SGU 495 Kids and Prizes(概率dp)
- sgu 495 Kids and Prizes 求概率
- Sgu 495 Kids and Prizes (概率dp)
- sgu 495 Kids and Prizes 概率dp
- SGU 495 Kids and Prizes 概率 二项分布
- SGU 495 Kids and Prizes (二项分布)
- SGU 495 Kids and Prizes 概率dp
- SGU 495 — Kids and Prizes
- C++之测试snmp的注册模块
- linux ssh自动登陆
- 文件操作
- PCL库尝试
- 小猪的Android入门之路 day 1
- SGU 495 Kids and Prizes [期望]
- c# 模拟表单提交,post form 上传文件、大数据内容
- 小猪的Android入门之路 Day 2
- 七步教你实现Django网站列表自动分页
- left join 和 inner join 以及 fetch
- 带扩展名的路由失效问题
- Redis入门很简单之三【常见参数配置】
- 卷积,DFT,FFT,图像FFT,FIR 和 IIR 的物理意义
- stm32_IAP