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 ...
随机推荐
- 不借助jquery封装好的ajax,你能用js手写ajax框架吗
不借助jquery封装好的ajax,你能手写ajax框架吗?最基础的ajax框架,一起来围观吧. .创建XMLHttpRequest对象 var xhr = new XMLHttpRequest(); ...
- c# 取 list前100条数据
[问] List<KeyWord> sortedList = (from a in keyWordList orderby a.Total descending select a).ToL ...
- 网站常用css必备css reset
在我们写前端代码页面的时候,很多常用的CSS类都是固定的!但没有一个标准或者大家都按自己的方式去随意的写,这样就每次都重复写一些固定的类! 为此HTML5 Doctor(HTML5医生)为我们总结了一 ...
- PHP字符串函数之 strstr stristr strchr strrchr
strstr -- 查找字符串的首次出现,返回字符串从第一次出现的位置开始到该字符串的结尾或开始. stristr -- strstr 函数的忽略大小写版本 strchr -- strstr 函数的别 ...
- 精华阅读第 9 期 |滴滴出行 iOS 客户端架构演进之路
「架构都是演变出来的,没有最好的架构,只有最合适的架构!」最近,滴滴出行平台产品中心 iOS 技术负责人李贤辉接受了 infoQ 的采访,阐述了滴滴的 iOS 客户端架构模式与演变过程.李贤辉也是移动 ...
- SDUT1591交叉排序
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1591&cid=1187 #include<cstdio> #include& ...
- spring3.0的jar包详解
1. spring.jar 是包含有完整发布模块的单个jar 包. 2. org.springframework.aop 包含在应用中使用Spring的AOP特性时所需的类. 3. org.sprin ...
- Spring的lazy-init详解
1.Spring中lazy-init详解ApplicationContext实现的默认行为就是在启动服务器时将所有singleton bean提前进行实例化(也就是依赖注入).提前实例化意味着作为初始 ...
- 快速学习bootstrap前台框架
W3c里的解释 使用bootstrap需要注意事项 1. 在html文件第一行要加上<!doctype html>[s1] 2. 导入bootstrap.min.css文件 3. 导 ...
- Orcle数据库查询练习复习:一
一.创建数据库和表 drop table student; create table student ( sid int, sname ), sage int, ssex ), snativeplac ...