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
随机推荐
- 安卓GreenDao(基础)
GreenDao的基础使用很简单,网上一大筐,推荐在简书里面搜索,那么我这里要说些什么呢,试想,这些简单的Demo可以带你了解GreenDao,但你能用这些代码做公司的项目么,肯定不行,所以我结合自身 ...
- Centos 7 安装 ELK 5.6.8 及基础的配置
下载 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.rpm wget https://ar ...
- linux普通帐号可以临时切换到root(添加用户到sudoers中)
一般,进入terminal之后,默认是普通账户能操作的功能,能访问的目录有限,需要临时切换到root账户 那么此时就需要配置sudoers文件,可以让普通用户通过sudo命令临时切换到root账户 首 ...
- 含服务端,客户端,数据库的注册/登录/聊天/在线/离线查看的聊天demo
用websocket,mysql,node的写了一个简单聊天的demo 实现了: 注册,登陆功能: 聊天信息广播: 在线/离线状态的查看: 服务端: 主要引用http,fs,mysql,socket. ...
- 0x16 Tire
参考链接:https://www.cnblogs.com/TheRoadToTheGold/p/6290732.html 题目链接:https://www.acwing.com/problem/con ...
- ssh到虚拟机---一台主机上
问题描述:我们需要ssh来编辑虚拟机中的文件,以此提高工作效率.但是新建的虚机一般来说没有开启ssh服务,所以需要在虚拟机上开启ssh服务. 1)检查是否安装了SSH rpm -qa |grep ss ...
- return -1 、return 1 、 return 0 的区别
根据所定义函数的需求返回不同的值. 一般0和-1或者0和1使用 0和-1使用时: 0一般表示成功执行 -1一般表示不成功 0和1使用时: 1真 0假
- 如何加速GitHub访问速度
http://tool.chinaz.com/网站中填入assets-cdn.github.com选取响应最小的ip,将ip.域名填入到C:\Windows\System32\drivers\etc下 ...
- vi编辑器使用记录
01. vi 简介 1.1 学习 vi 的目的 在工作中,要对 服务器 上的文件进行 简单 的修改,可以使用 ssh 远程登录到服务器上,并且使用 vi 进行快速的编辑即可 常见需要修改的文件包括: ...
- 北京AI外包团队 祝大家2019事业有事,大吉大利!
未来已来,以人工智能为核心的科技力量,在重新塑造着我们生活的环境.这种重新塑造的现象如此之明显,力量如此强大,以至于越来越多的人在讨论,我们面临着新一轮的工业革命.而且现在我们面临的这次新的科技力量, ...