https://vjudge.net/problem/UVA-10288

大街上到处在卖彩票,一元钱一张。购买撕开它上面的锡箔,你会看到一个漂亮的图案。

图案有n种,如果你收集到所有n(n≤33)种彩票,就可以得大奖。

请问,在平均情况下,需要买多少张彩票才能得到大奖呢?

答案以带分数形式输出

例:当n=5时

思路简单,就是输出麻烦

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
struct fraction
{
long long numerator;
long long denominator;
fraction()
{
numerator=;
denominator=;
}
fraction(long long num)
{
numerator=num;
denominator=;
}
fraction(long long a,long long b)
{
numerator=a;
denominator=b;
this->reduction();
}
void operator =(const long long num)
{
numerator=num;
denominator=;
this->reduction();
}
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);
fraction tmp=fraction(numerator*(b.denominator/gcdnum)+b.numerator*(denominator/gcdnum),denominator/gcdnum*b.denominator);
tmp.reduction();
return tmp;
}
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
{
fraction tmp=fraction(numerator*b.numerator,denominator*b.denominator);
tmp.reduction();
return tmp;
}
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(numerator,denominator);
numerator/=gcdnum;
denominator/=gcdnum;
}
void print()
{
if(denominator==) { printf("%lld\n",numerator); }
else
{
long long num=numerator/denominator;
long long tmp=num;
int len=;
while(tmp)
{
len++;
tmp/=;
}
for(int i=;i<=len;i++) printf(" ");
if(len) printf(" ");
printf("%lld\n",numerator%denominator);
if(num) printf("%lld ",num);
tmp=denominator;
while(tmp)
{
printf("-"); tmp/=;
}
puts("");
for(int i=;i<=len;i++) printf(" ");
if(len) printf(" ");
printf("%lld\n",denominator);
}
}
}f[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
f[]=;
for(int i=;i<=n;i++)
f[i]=f[i-]+fraction(,i);
f[n]=f[n]*n;
f[n].print();
}
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

    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种就有奖,问平均情况下买多少张才能中奖?用最简的分数形式表示答案.n<=33. 思路:这题实在好人,n<=33.用longlong ...

  5. UVA 10288 Coupons (概率)

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

  6. GCD LCM 最大公约数 最小公倍数 分数模板 (防溢出优化完成)

    自己写的一个分数模板,在运算操作时进行了防溢出的优化: ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } ll lcm(ll a, ll b) { ...

  7. UVa10288 Coupons 分数模版

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

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

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

  9. UVa 10288 (期望) Coupons

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

随机推荐

  1. 互评Alpha版本——基于NABCD评论作品,及改进建议

    组名:可以低头,但没必要 组长:付佳 组员:张俊余  李文涛  孙赛佳  田良  于洋  刘欣  段晓睿 一.杨老师粉丝群--<弹球学成语> 1.1 NABCD分析   N(Need,需求 ...

  2. Scrum立会报告+燃尽图(Beta阶段第六次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2388 项目地址:https://coding.net/u/wuyy694 ...

  3. postman的巨坑 之 cookie

    问题描述:一个后端接口,该接口需要校验登录态,登录态通过cookie中的一个传参k判断.在保证登录的前提下,调用机器A上的接口一直报“用户未登录”,调机器B上就没问题,于是开始排查问题. 解决过程: ...

  4. java调试器

    javac.exe是编译.java文件 java.exe是执行编译好的.class文件 javadoc.exe是生成Java说明文档 jdb.exe是Java调试器 javaprof.exe是剖析工具 ...

  5. tomcat启动时,报java.io.EOFException

    在启动Tomcat的时候突然报出IO异常,具体异常如下图 在网上找了解决方法,测试了好几种,都不行,到最后看了一个博客解决了,在此记录一下. 百度了下,网上都是说去Tomcat目录下:将tomcat5 ...

  6. 2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal

    题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定一个长度为2n,由n个大写字母和 ...

  7. App接口如何保证安全

    微信开发或者高德地图,百度地图什么的api要使用,使用之前都需要注册一个账号,然后系统会给你一个key,然后调用api的时候把key传给服务器. 平常公司内部开发项目时,直接用mvc为app客户端提供 ...

  8. 从理论到实践,全方位认识DNS

    从理论到实践,全方位认识DNS 2015-11-23 程序员之家 作者:selfboot 原文:http://segmentfault.com/a/1190000003956853 对于 DNS(Do ...

  9. SSH框架配置

    --------------------------------applicationContext.xml-------------------------------- <?xml vers ...

  10. DataTable Excel 导出:

    public static class CSVFileHelper { public static string ToHtmlTable(this DataTable target) { return ...