uva 10288 gailv
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的更多相关文章
- UVA 10288 - Coupons(概率递推)
UVA 10288 - Coupons option=com_onlinejudge&Itemid=8&page=show_problem&category=482&p ...
- Uva 10288 Coupons
Description Coupons in cereal boxes are numbered \(1\) to \(n\), and a set of one of each is require ...
- UVa 10288 - Coupons(数学期望 + 递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10288 (期望) Coupons
题意: 每张彩票上印有一张图案,要集齐n个不同的图案才能获奖.输入n,求要获奖购买彩票张数的期望(假设获得每个图案的概率相同). 分析: 假设现在已经有k种图案,令s = k/n,得到一个新图案需要t ...
- UVA 10288 Coupons---概率 && 分数类模板
题目链接: https://cn.vjudge.net/problem/UVA-10288 题目大意: 一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最 ...
- uva 10288 Coupons (分数模板)
https://vjudge.net/problem/UVA-10288 大街上到处在卖彩票,一元钱一张.购买撕开它上面的锡箔,你会看到一个漂亮的图案. 图案有n种,如果你收集到所有n(n≤33)种彩 ...
- UVA 10288 Coupons (概率)
题意:有n种纸片无限张,随机抽取,问平均情况下抽多少张可以保证抽中所有类型的纸片 题解:假设自己手上有k张,抽中已经抽过的概率为 s=k/n:那抽中下一张没被抽过的纸片概率为 (再抽一张中,两张中,三 ...
- UVA 10288 Coupons 彩票 (数学期望)
题意:一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最简的分数形式表示答案.n<=33. 思路:这题实在好人,n<=33.用longlong ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
随机推荐
- python-列表与元组
列表(List) 特性: 列表也是一种Sequence 类型 下标 能切片 可以存储任何类型的数据,每个元素是任意类型,可以存放任 ...
- Linq、Lambda表达式详细总结(转)
(一)输入参数 在Lambda表达式中,输入参数是Lambda运算符的 左边部分.它包含参数的数量可以为0.1或者多个.只有当输入参数为1时,Lambda表达式左边的一对小括弧才可以省略.输入参数的数 ...
- Gatling实战(一)
对Gatling早有耳闻,据说比jmeter的性能要好很多,我第一次试用的时候因为本机安装的jdk版本不对无法跑起来,试用失败后,因为没时间就一直没继续研究了.我当时是去java官网下载最新的jdk覆 ...
- Rabbit原理理解
1.RabbitMQ知多少 圣杰 2.[RabbitMQ]——三种Exchange模式(Fanout.Direct.Topic) https://blog.csdn.net/hao134838/a ...
- elasticsearch搭建并通过go-mysql-elasticsearch同步db数据达到搜索引擎的目的
logstash-input-jdbc/elasticsearch-jdbc缺点:删除记录没有办法同步,只能两边执行自己的删除命令,版本16年后未更新. go-mysql-elasticsearch缺 ...
- 基于SVD的图像压缩
算法简介 算法实现 我只是简单处理了一下图像的灰度值,如果要处理RGB值的话,就需要分别进行SVD分解,最后再合起来即可. import numpy as np from PIL import Ima ...
- Jenkins去GitLab拉取Java代码自动打包
jenkins的部署 一.部署git 1)先检查系统是否已经自带了git,如果有,就卸载 $ rpm -qa | grep git && rpm -e git --nodeps 2)开 ...
- VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...
- InstallShield Limited Edition for Visual Studio 使用
首先到https://info.flexerasoftware.com/IS-EVAL-InstallShield-Limited-Edition-Visual-Studio填写信息: 完成之后跳转到 ...
- kafka可视化客户端工具Kafka Tool
1.下载 下载地址:http://www.kafkatool.com/download.html 2.安装 根据不同的系统下载对应的版本,我这里kafka版本是1.1.0,下载kafka tool 2 ...