UVA 题目10288 Coupons(期望)
来源:互联网 发布:linux php ext 目录 编辑:程序博客网 时间:2024/05/21 09:54
Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a prize (a cereal
box, of course). With one coupon per box, how many boxes on average are required to make a complete
set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1 ≤ n ≤ 33, giving the
size of the set of coupons. Input is terminated by end of file.
Output
For each input line, output the average number of boxes required to collect the complete set of n
coupons. If the answer is an integer number, output the number. If the answer is not integer, then
output the integer part of the answer followed by a space and then by the proper fraction in the format
shown below. The fractional part should be irreducible. There should be no trailing spaces in any line
of output.
Sample Input
2
5
17
Sample Output
3
5
11 --
12
340463
58 ------
box, of course). With one coupon per box, how many boxes on average are required to make a complete
set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1 ≤ n ≤ 33, giving the
size of the set of coupons. Input is terminated by end of file.
Output
For each input line, output the average number of boxes required to collect the complete set of n
coupons. If the answer is an integer number, output the number. If the answer is not integer, then
output the integer part of the answer followed by a space and then by the proper fraction in the format
shown below. The fractional part should be irreducible. There should be no trailing spaces in any line
of output.
Sample Input
2
5
17
Sample Output
3
5
11 --
12
340463
58 ------
720720
题目大意:n个球放在n个盒子里,每次取每个盒子的概率一样,问取出n个球的期望是多少
ac代码
#include<stdio.h>#include<algorithm>#include<stdlib.h>#include<iostream>#include<math.h>#define LL long longusing namespace std;LL gcd(LL a,LL b){ if(a<b) { swap(a,b); } if(b==0) return a; return gcd(b,a%b);}int fun(LL x){ int ans=0; while(x) { x/=10; ans++; } return ans;}int main(){ LL n; while(scanf("%lld",&n)!=EOF) { LL i; LL fz=n,fm=n; for(i=1;i<n;i++) { fz=fz*(n-i)+n*fm; fm=fm*(n-i); LL Gcd=gcd(fm,fz); fm/=Gcd; fz/=Gcd; } if(fm==1) { printf("%lld\n",fz); } else { LL fi; fi=fz/fm; fz%=fm; int c1=fun(fi); int c2=max(fun(fz),fun(fm)); for(i=0;i<c1;i++) printf(" "); printf(" %lld\n",fz); printf("%lld ",fi); for(i=0;i<c2;i++) printf("-"); printf("\n"); for(i=0;i<c1;i++) printf(" "); printf(" %lld\n",fm); } }}
0 0
- UVA 题目10288 Coupons(期望)
- uva 10288 Coupons 数学期望
- UVA 10288 Coupons 数学期望
- 10288 - Coupons (数学期望)
- UVa 10288(Coupons) 数学期望(概率+递推) Java
- uva 10288 Coupons 数学期望,分数计算表示
- 【UVA】10288-Coupons(概率)
- UVA - 10288 Coupons (概率+递推)
- Uva 10288 Coupons (概率dp)
- Uva 10288 - Coupons
- UVA 10288 - Coupons
- uva 10288 coupons
- UVA 10288 Coupons
- uva 10288 - Coupons(概率)
- UVA 10288 - Coupons
- UVa 10288 Coupons
- UVA 10288(p333)----Coupons
- uva 10288 Coupons
- Linux网络通信总结
- ZooKeeper三种模式-伪集群
- 情诗
- day10-枚举、typedef、宏、声明
- 珠联璧合之WAS社区版与HTTP Server
- UVA 题目10288 Coupons(期望)
- 2015罗辑思维跨年演讲浓缩精华版整理
- OpenCV dnn模块支持Caffe
- 秒杀系统架构分析与实战
- CRF++的使用
- ERP原理学习3-5
- ZooKeeper三种模式-集群
- 生日选择器
- python学习之常量