题目:

题意:

一共n种不同的礼券,每次得到每种礼券的概率相同。求期望多少次可以得到所有n种礼券。结果以带分数形式输出。1<= n <=33.

思路:

假设当前已经得到k种,获得新的一种的概率是(n-k)/n,则对应期望是n/(n-k)。求和得到步数期望是n/n+n/(n-1)+...+n/1=n*sum(1/i) (1<= i <= n)。需要注意及时约分,用分数类模板。

程序:

 #include <cstdio>
#include <cassert>
#include <cstdlib> long long gcd (long long a, long long b) {
return b == ? a : gcd(b, a % b);
} class fraction {
public:
fraction() {
numerator = ;
denominator = ;
}
fraction(long long num) {
numerator = num;
denominator = ;
}
fraction (long long a, long long b) {
assert(b != );
if (b < ) {
numerator = -a;
denominator = -b;
} else {
numerator = a;
denominator = b;
}
this->reduction();
} void operator = (long long num) {
numerator = num;
denominator = ;
} void operator = (const fraction &b) {
numerator = b.numerator;
denominator = b.denominator;
this->reduction();
} fraction operator + (const fraction &b) const {
long long gcdnum = gcd(denominator, b.denominator);
return fraction(numerator*(b.denominator/gcdnum) + b.numerator*(denominator/gcdnum), denominator/gcdnum*b.denominator);
} fraction operator + (const int b) const {
return ((*this) + fraction(b));
} fraction operator - (const fraction &b) const {
return ((*this) + fraction(-b.numerator, b.denominator));
} fraction operator - (const int &b) const {
return ((*this) - fraction(b));
} fraction operator * (const fraction &b) const {
return fraction(numerator*b.numerator, denominator * b.denominator);
} fraction operator * (const int &b) const {
return ((*this) * fraction(b));
} fraction operator / (const fraction &b) const {
return ((*this) * fraction(b.denominator, b.numerator));
} void reduction() {
if (numerator == ) {
denominator = ;
return;
}
long long gcdnum = gcd(abs(numerator), denominator);
numerator /= gcdnum;
denominator /= gcdnum;
} public:
long long numerator;//分子
long long denominator;//分母
}; int countLen (long long n) {
int m = ;
while (n) {
n /= ;
m++;
}
return m;
} void printF (const fraction &f){
long long a, b, c;
int m, n;
b = f.numerator;
c = f.denominator;
if (c == (long long)) {
printf("%lld\n", b);
} else {
a = b / c;
m = countLen(a);
b -= a * c;
n = countLen(c);
for (int i = ; i <= m; i++) {
printf(" ");
}
printf("%lld\n%lld ", b, a);
for (int i = ; i < n; i++) {
printf("-");
}
puts("");
for (int i = ; i <= m; i++) {
printf(" ");
}
printf("%lld\n", c);
}
} int main() {
int n, maxn = ;
fraction f[maxn + ]; for (int i = ; i <= maxn; i++) {
f[i] = f[i - ] + fraction(, i);
} while (~scanf("%d", &n)) {
printF(f[n] * n);
} return ;
}

uva10288 Coupons 【概率 分数】的更多相关文章

  1. UVa10288 Coupons 分数模版

    UVa10288 题目非常简单, 答案就是 n/n+n/(n-1)+...+n/1; 要求分数输出.套用分数模板.. #include <cstdio> #include <cstr ...

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

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

  3. [POJ2625][UVA10288]Coupons

    Description Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a ...

  4. 「SHOI2002」「LuoguP1291」百事世界杯之旅(UVA10288 Coupons)(期望,输出

    题目描述 “……在2002年6月之前购买的百事任何饮料的瓶盖上都会有一个百事球星的名字.只要凑齐所有百事球星的名字,就可参加百事世界杯之旅的抽奖活动,获得球星背包,随声听,更克赴日韩观看世界杯.还不赶 ...

  5. uva 10288 Coupons (分数模板)

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

  6. ID3、C4.5、CART、RandomForest的原理

    决策树意义: 分类决策树模型是表示基于特征对实例进行分类的树形结构.决策树可以转换为一个if_then规则的集合,也可以看作是定义在特征空间划分上的类的条件概率分布. 它着眼于从一组无次序.无规则的样 ...

  7. Logistic Regression vs Decision Trees vs SVM: Part II

    This is the 2nd part of the series. Read the first part here: Logistic Regression Vs Decision Trees ...

  8. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  9. 学习笔记TF052:卷积网络,神经网络发展,AlexNet的TensorFlow实现

    卷积神经网络(convolutional neural network,CNN),权值共享(weight sharing)网络结构降低模型复杂度,减少权值数量,是语音分析.图像识别热点.无须人工特征提 ...

随机推荐

  1. oracle之 安装 11G RAC 报 NTP failed

    问题描述: 使用 NTP 同步集群节点时间,安装 11G RAC 报 NTP 过不去. 解决过程:-- 查看 /etc/sysconfig/ntpd 文件配置root@hbdw1:/root$cat ...

  2. android adb端口被占用解决方法

    1.输入adb devices命令 C:\Users\Nick>adb devices List of devices attached adb server version (31) does ...

  3. panabit允许一台代理服务器只能收QQ企业邮箱,和内网ip通讯,限制除了QQ企业邮箱以外的所有内容规则

    环境: 可访公网网的内网网段:192.168.0.0/24(员工网段)  192.168.2.0/24(服务器网段)两个内网网段. 不能访问公网的内网网段:192.168.4.0/24 4网段利用fo ...

  4. zeromq测试

    debian sudo apt-get install libzmq3-dev pip install zmq client.py #coding: utf-8 import zmq context ...

  5. emacs之配置8,gdb调试设置

    emacsConfig/gdb-setting.el (global-set-key [(f5)] 'gud-go) (global-set-key [(f7)] 'gud-step) (global ...

  6. VS2017开发Linux平台上的程序

    重装系统后安装VS2015时卡住了,于是试试看VS2017怎样,听说还支持调Linux.发现VS2017跟12/13/15又有了新的飞跃,竟然支持模块化下载,对于我这种主要写C++简直是个福音,勾了L ...

  7. NPOI-Excel系列-1000.创建一个标准的Excel文件

    using NPOI.HSSF.UserModel; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; name ...

  8. C#中XML文档注释编译DLL引用到其它项目

    引用地址:http://zhidao.baidu.com/link?url=jSGYEBysE4gBExtNsHCVk3vd2OK2cMlaf02cS79GdRuGueTBdFJB0btOdBYkg_ ...

  9. java get post 请求

    package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...

  10. POJ 1061 青蛙的约会(拓展欧几里得求同余方程,解ax+by=c)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 122871   Accepted: 26147 Descript ...