题意:

每张彩票上印有一张图案,要集齐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的更多相关文章

  1. UVA 10288 - Coupons(概率递推)

    UVA 10288 - Coupons option=com_onlinejudge&Itemid=8&page=show_problem&category=482&p ...

  2. UVa 10288 - Coupons(数学期望 + 递推)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA 10288 Coupons 彩票 (数学期望)

    题意:一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最简的分数形式表示答案.n<=33. 思路:这题实在好人,n<=33.用longlong ...

  4. Uva 10288 Coupons

    Description Coupons in cereal boxes are numbered \(1\) to \(n\), and a set of one of each is require ...

  5. uva 10288 Coupons (分数模板)

    https://vjudge.net/problem/UVA-10288 大街上到处在卖彩票,一元钱一张.购买撕开它上面的锡箔,你会看到一个漂亮的图案. 图案有n种,如果你收集到所有n(n≤33)种彩 ...

  6. UVA 10288 Coupons (概率)

    题意:有n种纸片无限张,随机抽取,问平均情况下抽多少张可以保证抽中所有类型的纸片 题解:假设自己手上有k张,抽中已经抽过的概率为 s=k/n:那抽中下一张没被抽过的纸片概率为 (再抽一张中,两张中,三 ...

  7. uva 10288 gailv

    Problem F Coupons Input: standard input Output: standard output Time Limit: seconds Memory Limit: MB ...

  8. 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/ ...

  9. 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 ...

随机推荐

  1. js获取对象、数组的实际长度,元素实际个数

    /*获取对象.数组的长度.元素个数 *@param obj 要计算长度的元素,可以为object.array.string */ function count(obj){ var objType = ...

  2. BZOJ 1143: [CTSC2008]祭祀river 最大独立集

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1143 题解: 给你一个DAG,求最大的顶点集,使得任意两个顶点之间不可达. 把每个顶点v ...

  3. 【Asp.Net MVC-视频】

    Asp.Net MVC官网网发布的pluralsight视频教学: http://pluralsight.com/training/Player?author=scott-allen&name ...

  4. crontab 不能执行git命令问题备忘

    这问题够隐蔽,折腾了近两个小时. 命令 git checkout tagname 手工执行都正常 但在crontab运行时发现分支一直切不过去. 后来告诉是crontab默认的 path  设置和系统 ...

  5. hdu 1713 相遇周期

    求分数的最小公倍数.对于a/b c/d 先化简为最简分数,分数最小公倍数=分子的最小公倍数/分母的最大公约数. ;}

  6. hdu 1002 A+B

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1002 复习一下大数 模板: #include <stdio.h> #include <s ...

  7. js call apply bind简单的理解

    相同点:JS中call与apply方法可以改变某个函数执行的上下文环境,也就是可以改变函数内this的指向.区别:call与apply方法的参数中,第一个参数都是指定的上下文环境或者指定的对象,而ca ...

  8. 李洪强iOS开发之OC[015]#pragma mark的使用

    // //  main.m //  14 - #pragma mark的使用 // //  Created by vic fan on 16/7/10. //  Copyright © 2016年 李 ...

  9. Project Euler 86:Cuboid route 长方体路径

    Cuboid route A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, ...

  10. C++primer中的TextQuery(读取文本)

    本题目对应于 C++primer(第四版)中 第十章的文本查询类(TextQuery) 用到的知识有: 顺序容器 vector 关联容器 set,map 标准输入输出流,文件流,字符串流 //写一个文 ...