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. 【每日scrum】NO.8

    (1) 在图的设计过程中掌握了图的基本运算函数的算法的理解和程序的有效吸收,包括图的深度和广度优先的遍历,对图的联通分量的求解,图的最小生成树,图的拓扑排序,图的关键路径, (2)在迪杰斯特拉算法的基 ...

  2. 软工实践-Alpha 冲刺 (4/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 很胖,刚学,照猫画虎做了登录与注册界面. 展示GitHub ...

  3. sql主表分页查询关联子表取任意一条高效方案

    有个业务场景,主表中一条数据,在子表中有多条详情数据.对数据进行展示的时候,产品希望随意拿一条子表的数据关联展示出来,用了很多方案,但是都不够好. sql查询取子表任意一条,多个字段的方案 最终找到一 ...

  4. Strust2: 工作流程

    以下为Struts2的体系结构图: Struts2框架处理用户请求,大体分为以下几个过程: (1)用户发出一个HttpServletRequest请求 (2)请求经过一系列过滤器,最后达到Filter ...

  5. 解决因生成javadoc失败导致Maven打包失败问题

    方案就是设置javadoc生成失败时不导致整个打包失败: <plugin> <groupId>org.apache.maven.plugins</groupId> ...

  6. haproxy调度算法

    调度算法详解 用balance指令指明调度算法, 例如:balance roundrobin   1:roundrobin :动态轮询算法,基于后端服务器的总权重做轮询,后端的服务器数量限制在4095 ...

  7. [2017BUAA软工]第二次博客作业:代码复审

    〇.comment链接 https://github.com/hanayashiki/Sudoku/issues/1 一.代码复审 1.概要部分 (1)代码能符合需求和规格说明么? 经测试,对于合法输 ...

  8. PAT L1-034 点赞

    https://pintia.cn/problem-sets/994805046380707840/problems/994805098188750848 微博上有个“点赞”功能,你可以为你喜欢的博文 ...

  9. [Code Festival 2017 qual A] B: flip

    题意 给出一个n行m列初始全白的矩阵,每次可以翻转一行/一列的全部格子的颜色.问任意次操作后能否使得恰好有k个黑色格子. n,m<=1000 分析 显然要么翻转一次要么不翻转. 最终黑色格子数只 ...

  10. 【hdu5306】Gorgeous Sequence 线段树区间最值操作

    题目描述 给你一个序列,支持三种操作: $0\ x\ y\ t$ :将 $[x,y]$ 内大于 $t$ 的数变为 $t$ :$1\ x\ y$ :求 $[x,y]$ 内所有数的最大值:$2\ x\ y ...