uva 10288 coupons
来源:互联网 发布:美工作品图片幼儿园 编辑:程序博客网 时间:2024/05/21 08:46
Problem F
Coupons
Input: standard input
Output: standard output
Time Limit: 2 seconds
Memory Limit: 32 MB
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 ------
720720
题目大意:一共有n中不同的优惠券 ,每次得到每种优惠券的概率相同。问期望多少次可以得到所有n种优惠券。 a <= n <= 33
(吐槽一下原题目 ,英文的也很短 ,妈蛋看了半个小时没读懂,好歹也是过了六级的人,果然智商有限)
其实感觉这道题是下面这样的一道题的推广
抛一枚均匀的硬币直到出现k次正面为止,试求抛掷次数X的数学期望。
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <cstdlib>#include <cassert>using namespace std;typedef long long LL;LL n, r;LL p, q;LL gcd(LL a, LL b){if(b == 0){return a;}return gcd(b, a % b);}void reduction(LL &a, LL &b){LL d = gcd(a, b);a /= d;b /= d;}void addF(int a, int b){p = p * b + a * q;//cout << p << " " ;q *= b;reduction(p, q);}void printF(LL p){LL rr = r;while(rr){printf(" ");rr /= 10;}printf(" ");printf("%lld\n", p);}int main(){#ifdef DEBUGFILE *fPtr = freopen("a.in", "r", stdin);assert(fPtr != NULL);fPtr = freopen("a.out", "w", stdout);assert(fPtr != NULL);#endifwhile(scanf("%lld", &n) == 1){p = 0LL, q = 1LL;r = n;for(LL i = 1; i <= n; i++){addF(1, i);}//cout << p << " " << q << endl;reduction(r, q);p *= r;//cout << "p = " << r << endl;r = p / q;p %= q;if(p % q == 0){printf("%lld\n", r);}else{printF(p);printf("%lld ", r);LL qq = q;while(qq){printf("-");qq /= 10;}printf("\n");printF(q);}}return 0;}
- 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
- uva 10288 Coupons
- Uva 10288 Coupons
- UVA 10288 Coupons
- Coupons - UVa 10288 概率dp
- 【UVA】10288-Coupons(概率)
- uva 10288 Coupons 数学期望
- UVA 10288 Coupons 数学期望
- Coupons UVA
- UVA 10288 - Coupons(概率递推)
- JavaScript之函数
- CentOS6.4+ 安装firefox最新版
- 1783:完数
- Linux 常用命令总结(不断补充中……)
- 【重温数据库知识】用SQL语句实现:学生表、课程表、选课表三张表中的问题
- uva 10288 coupons
- java实现简单的单点登录
- ajax对象初始化-原始代码记录
- JAVA 交集,差集,并集
- C++中extern “C”含义深层探索
- Activity与Intent
- eclipse加载maven工程提示pom.xml无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3解决方案
- mac pro升级内存和更换SSD硬盘
- cocos2d-x学习资料