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 ...
随机推荐
- 【BZOJ】【1115】【POI2009】石子游戏KAM
博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...
- bzoj 3907: 网格 组合数学
3907: 网格 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 13 Solved: 7[Submit][Status][Discuss] Descr ...
- 如何深入理解 StatsD 与 Graphite ?
众所周知,StatsD 负责收集并聚合测量值.之后,它会将数据传给 Graphite,后者以时间序列为依据存储数据,并绘制图表.但是,我们不知道,基于 http 访问的图表在展示时,是基于每秒钟的请求 ...
- EF提供的三种查询方式
這邊簡單介紹一下,ADO.Net Entity Framework 提供的三種查詢方式, Linq to Entities Query Builder Mothed Entity SQL Langua ...
- 【面试题004】c/c++字符串,替换空格
一,c/c++字符串 1.C/C++中每个字符串都以字符’\0‘作为结尾,这样我们就能很方便地找到字符串的最后尾部. 由于这个原因每个字符串都有一个额外的开销,注意字符串越界的问题: 2.C/C+ ...
- Browser detect
A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give s ...
- 02 - 用wxStreamToTextRedirector和wxTextCtrl输出std::cout
遇到问题,单行显示, new line丢失 原因: wxTextCtrl默认是单行的 解决办法:使用wxTE_MULTILINE参数初始化wxTextCtrl wxTextCtrl *text = , ...
- linux网站推荐
推荐几个Liux中文学些网站. http://www.chinaunix.net/http://linux.cn/http://www.linuxidc.com/
- jQuery动画效果实现
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Tomcat部署Web应用方法总结
转载:http://m.blog.csdn.net/blog/u012516903/15741727 Tomcat部署Web应用方法总结 在Tomcat中部署Java Web应用程序有两种方式:静态部 ...