博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kids and Prizes(SGU 495)
阅读量:4518 次
发布时间:2019-06-08

本文共 3253 字,大约阅读时间需要 10 分钟。

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 Nprizes 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

 两种方法:

1.设A = “所有奖品都不被取到”, P(A) = ((n - 1) / n) ^ m;

E(A) =  n * P(A);

E(!A) = n - E(A);

2.P(i) 表示第i个人拿到奖品的概率;

P(i) = P(i - 1) * (1 - P(i - 1)) + P(i - 1) * (P(i - 1) - 1 / n);

E = ∑(P(i) * 1);

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define _cle(m, a) memset(m, a, sizeof(m))#define repu(i, a, b) for(int i = a; i < b; i++)#define MAXN 100005double d[MAXN];int main(){ double n, m; while(~scanf("%lf%lf", &n, &m)) { d[1] = 1.0; for(int i = 2; i <= (int)m; i++) d[i] = (1.0 - d[i - 1]) * d[i - 1] + d[i - 1] * (d[i - 1] - 1.0 / n); double e = 0.0; for(int i = 1; i <= (int)m; i++) e += d[i]; printf("%.10lf\n", e); } return 0;}
View Code
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define _cle(m, a) memset(m, a, sizeof(m))#define repu(i, a, b) for(int i = a; i < b; i++)#define MAXN 1005int main(){ double n, m; while(~scanf("%lf%lf", &n, &m)) printf("%.9lf\n", n - n * pow((n - 1) / n, m)); return 0;}
View Code

 

转载于:https://www.cnblogs.com/sunus/p/4425585.html

你可能感兴趣的文章
angularjs1-7,供应商
查看>>
BitSet
查看>>
Spring常用注解,自动扫描装配Bean
查看>>
(转载)深入理解WeakHashmap
查看>>
JAVA中的数组
查看>>
爬虫—使用Requests
查看>>
scrollIntoView()窗口滚动
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
使用ansible远程管理集群
查看>>
读jQuery源码释疑笔记3
查看>>
手把手教你jmeter压测--适合入门
查看>>
Sequelize+MySQL存储emoji表情
查看>>
RabbitMQ学习之Publish/Subscribe(3)
查看>>
[SCOI2010]生成字符串
查看>>
JLOI2015 城池攻占
查看>>
在 Azure 虚拟机上快速搭建 MongoDB 集群
查看>>
跑步运动软件调研
查看>>
搭建ntp时间服务器 ntp - (Network Time Protocol)
查看>>
35. Search Insert Position
查看>>
awk使用
查看>>