Problem F

Coupons

Input: standard input

Output: standard output

Time Limit:  seconds

Memory Limit:  MB

Coupons in cereal boxes are numbered  to n, and a set of one of each is required for a prize (a cereal box, of course). With one coupon per box, how many boxes on average are required to make a complete set ofn coupons?

Input

Input consists of a sequence of lines each containing a single positive integern, <=n<=, giving the size of the set of coupons. Input is terminated by end of file.

Output

For each input line, output the average number of boxes required to collect the complete set ofn coupons. If the answer is an integer number, output the number. If the answer is not integer, then output the integer part of the answer followed by a space and then by the proper fraction in the format shown below. The fractional part should be irreducible. There should be no trailing spaces in any line of output.

Sample Input

Sample Output

 --

 ------

记得每次求gcd不然会爆掉。 思路:到k张时。我们还有n-k张没有得到。所以我们得到的概率为n-k/n;

所以到k+1步的期望时n/n-k;

整理得 n* 1/i(n>i>1)的累加

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
ll gcd(ll n,ll m)
{
if(m==)
return n;
return gcd(m,n%m);
}
int geth(ll x)
{
int ans=;
while(x>)
{
x=x/;
ans++;
}
return ans;
}
int main()
{
ll n;
while(~scanf("%lld",&n))
{ ll fenmu=;
ll temp=;
for(int i=;i<=n;i++)
{
temp=gcd(fenmu,i);
fenmu=fenmu*i/temp;
}
ll fenzi=;
for(int i=;i<=n;i++)
{
fenzi+=fenmu/i; }
fenzi=fenzi*n;
ll p=gcd(fenzi,fenmu);
fenzi/=p;
fenmu/=p;
ll t=fenzi/fenmu;
if(fenzi-fenmu*t>)
{
if(t!=)
{
ll a=geth(t);
for(int i=;i<=a;i++)
{cout<<" ";}
cout<<fenzi-fenmu*t;
ll b=geth(fenzi-fenmu*t);
ll c=geth(fenmu);
if(b>c)
c=b;
cout<<endl;
cout<<t<<" ";
for(int i=;i<=c;i++)
{cout<<"-";}
cout<<endl;
for(int i=;i<=a;i++)
{cout<<" ";}
cout<<fenmu<<endl;
}
}
else
cout<<t<<endl; } return ;
}

uva 10288 gailv的更多相关文章

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

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

  2. Uva 10288 Coupons

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

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

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

  4. UVa 10288 (期望) Coupons

    题意: 每张彩票上印有一张图案,要集齐n个不同的图案才能获奖.输入n,求要获奖购买彩票张数的期望(假设获得每个图案的概率相同). 分析: 假设现在已经有k种图案,令s = k/n,得到一个新图案需要t ...

  5. UVA 10288 Coupons---概率 && 分数类模板

    题目链接: https://cn.vjudge.net/problem/UVA-10288 题目大意: 一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最 ...

  6. uva 10288 Coupons (分数模板)

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

  7. UVA 10288 Coupons (概率)

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

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

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

  9. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

随机推荐

  1. 三极管(如NPN)集电极正偏 发射极反偏会怎么样呢? 电流会倒流吗? 其他三种都知道,就是不知道这种情况

    三极管除了你知道的放大,饱和和截止三种工作状态之外,还有一种用得极少的“倒置”工作状态,就是集电结正偏发射结反偏,这时跟对比放大状态的发射结正偏集电结反偏来理解,“倒置状态”的集电结,发射结分别充当了 ...

  2. 2018-2019-2 网络对抗技术 20165305 Exp4 恶意代码分析

    Exp4 恶意代码分析 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysi ...

  3. C#通过Ado.net对连接数据库并进行添加删除等常规操作的代码

    如下资料是关于C#通过Ado.net对连接数据库并进行添加删除等常规操作的内容. static string sqlcon = "server=.;database=;Integrated ...

  4. linux用户键拷贝文件

    如果A用户没有权限写B用户下面的文件,可以用这个命令拷贝 scp AAA.tar.gz B用户名@IP:全路径

  5. CCF CSP 201712-1 最小差值

    题目链接:http://118.190.20.162/view.page?gpid=T68 问题描述 试题编号: 201712-1 试题名称: 最小差值 时间限制: 1.0s 内存限制: 256.0M ...

  6. eclipse上的.properties文件中文编辑显示问题

    安装 装Properties Editor插件,方法: Help --> Install New Software -->输入:http://propedit.sourceforge.jp ...

  7. python:更改pip源

    windows更改pip源 cmd echo %APPDATA% 打开目录 创建文件夹pip 创建pip.ini文件 [global] timeout = 60 index-url = http:// ...

  8. 单元测试系列之九:Sonar 常用代码规则整理(一)

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 摘要:公司部署了一套sonar,经过一段时间运行,发现有一些问题出现频率很高,因此有必要将这些问题进行整理总结和分 ...

  9. HTML有哪些标签?html常用标签大全

    html中标签有很多,每一种标签都有着不同的用处,下面这篇文章php中文网给大家总结html常用的标签,每一种标签都会跟随一个例子,话不多说,让我们来看看具体内容.<font>字体标签,用 ...

  10. [译]RabbitMQ教程C#版 - 主题

    先决条件 本教程假定 RabbitMQ 已经安装,并运行在localhost标准端口(5672).如果你使用不同的主机.端口或证书,则需要调整连接设置. 从哪里获得帮助 如果您在阅读本教程时遇到困难, ...