UVa 10288 (期望) Coupons
题意:
每张彩票上印有一张图案,要集齐n个不同的图案才能获奖。输入n,求要获奖购买彩票张数的期望(假设获得每个图案的概率相同)。
分析:
假设现在已经有k种图案,令s = k/n,得到一个新图案需要t次的概率为:st-1(1-s);
因此,得到一个新图案的期望为(1-s)(1 + 2s + 3s2 + 4s3 +...)
下面求上式中的级数:
令
则
所以得到一个新图案的期望为:
总的期望为:
这道题的输出很新颖,如果是分数的话,就要以分数形式输出,具体细节详见代码。
#include <iostream>
#include <sstream>
#include <cstdio>
using namespace std;
typedef long long LL; LL gcd(LL a, LL b)
{
if(b == ) return a;
return gcd(b, a % b);
} LL lcm(LL a, LL b)
{
return a / gcd(a, b) * b;
} int LL_length(LL x)
{
stringstream ss;
ss << x;
return ss.str().length();
} void print_chars(char c, int n)
{
for(int i = ; i < n; ++i)
putchar(c);
} void output(LL a, LL b, LL c)
{
if(b == )
{
printf("%lld\n", a);
return;
}
int l = LL_length(a);
print_chars(' ', l+);
printf("%lld\n", b);
printf("%lld ", a);
print_chars('-', LL_length(c));
printf("\n");
print_chars(' ', l+);
printf("%lld\n", c);
} int main()
{
int n;
while(scanf("%d", &n) == )
{
if(n == )
{
puts("");
continue;
}
LL x = , a = n + , b = , c;
for(int i = ; i <= n-; ++i)
x = lcm(x, i);
c = x;
x *= n;
for(int i = ; i <= n-; ++i)
b += x / i;
a += b / c;
LL g = gcd(b, c);
b /= g, c /= g;
b %= c;
output(a, b, c);
} return ;
}
代码君
UVa 10288 (期望) Coupons的更多相关文章
- UVA 10288 - Coupons(概率递推)
UVA 10288 - Coupons option=com_onlinejudge&Itemid=8&page=show_problem&category=482&p ...
- UVa 10288 - Coupons(数学期望 + 递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10288 Coupons 彩票 (数学期望)
题意:一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最简的分数形式表示答案.n<=33. 思路:这题实在好人,n<=33.用longlong ...
- Uva 10288 Coupons
Description Coupons in cereal boxes are numbered \(1\) to \(n\), and a set of one of each is require ...
- uva 10288 Coupons (分数模板)
https://vjudge.net/problem/UVA-10288 大街上到处在卖彩票,一元钱一张.购买撕开它上面的锡箔,你会看到一个漂亮的图案. 图案有n种,如果你收集到所有n(n≤33)种彩 ...
- UVA 10288 Coupons (概率)
题意:有n种纸片无限张,随机抽取,问平均情况下抽多少张可以保证抽中所有类型的纸片 题解:假设自己手上有k张,抽中已经抽过的概率为 s=k/n:那抽中下一张没被抽过的纸片概率为 (再抽一张中,两张中,三 ...
- uva 10288 gailv
Problem F Coupons Input: standard input Output: standard output Time Limit: seconds Memory Limit: MB ...
- UVa 11762 (期望 DP) Race to 1
设f(x)表示x转移到1需要的次数的期望,p(x)为不超过x的素数的个数,其中能整除x的有g(x)个 则有(1-g(x)/p(x))的概率下一步还是转移到x,剩下的情况各有1/p(x)的概率转移到x/ ...
- UVa 11427 (期望 DP) Expect the Expected
设d(i, j)表示前i局每局获胜的比例均不超过p,且前i局共获胜j局的概率. d(i, j) = d(i-1, j) * (1-p) + d(i-1, j-1) * p 则只玩一天就就不再玩的概率Q ...
随机推荐
- Careercup - Facebook面试题 - 4922014007558144
2014-05-01 02:13 题目链接 原题: Design question: Say you have hacked in to a network and can deploy your b ...
- android studio 智能提示忽略大小写
Step1: Step2:
- C#笔记2:重构
转: 最常用的重构指导 参考:http://www.cnblogs.com/KnightsWarrior/archive/2010/06/30/1767981.html,本文示例代码多来自此处: 参考 ...
- [bzoj 2159]Crash的文明世界
今天看到一个鬼题 心情好的时候写 [题意]求树上所有点对距离的k次方和,所有边权为1 大爷方的题解:http://tonyfang.is-programmer.com/posts/204972.htm ...
- ReplicaManager之DelayedOperation
DelayedOperation包括两种:DelayedFetch和DelayedProduce,它们的存在是由Kafka Protocol决定的,而Kafka Protocol是由实际需求决定的…… ...
- Unity3D研究院之与Android相互传递消息
原地址:http://www.xuanyusong.com/archives/676 上一篇文章我们学习了Unity向Android发送消息,如果Android又能给Unity回馈消息那么这就玩美了. ...
- python的dict()函数
dict(one=1,two=2) dict({'one':1,'two':2}) dict((('one',1),('two',2))) dict((['one',1],['two',2])) di ...
- SQL SERVER(MSSQLSERVER) 服务无法启用 特定服务错误:126
SQL SERVER(MSSQLSERVER) 服务无法启用 特定服务错误:126 对于这样一个错误google了一下 说是 要禁止掉via才行 回到SQL配置管理器中 禁止掉via 果然可以重新 ...
- struts2学习笔记(2)——简单的输入验证以及标签库的运用
struts2自带了一些标签库,运用好这些标签库会减少开发周期. 1.struts2标签库是在哪定义的? struts2标签库定义在struts2-core-2.1.8.jar这个文件中,具体在这个j ...
- [主席树]HDOJ3874 Necklace
题意:n个数 m个询问 询问的是[l, r]区间内不同的数的和 没有修改,静态的主席树即可 与 SPOJ QUERY 一样 将重复的元素建树即可 注意范围:$N \le 50000$ 每个值不超过1 ...