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
随机推荐
- 解决 IntelliJ IDEA Tomcat 控制台中文输出乱码问题
解决办法 找到安装IDEA的bin目录将idea.exe.vmoptions和idea64.exe.vmoptions两个文件打开分别在文件最末尾添加-Dfile.encoding=UTF-8
- 使用Jmeter连接MySql数据库
准备条件: 1.在MySql中创建数据库和表 2.MySql的驱动jra包 操作步骤: 1.将MySql的驱动jra包放入Jmetre本地文件夹的lib目录下 2.新建一个线程组,在线程组上 添加-配 ...
- iOS SDWebImage知识点
1.clear 和 clean clear 先把之前的缓存文件夹删除掉,然后新建一个文件夹 clean 先删除过期的文件,然后计算剩余缓存文件的大小 currentSize > maxSize, ...
- time模块和os模块,json模块
import time # def month(n): # time.local() # struct_time=time.strptime("%Y-%m-1","%Y- ...
- Java基础学习-Random类和Java数组
1.随机数类(Random) package com.denniscui; import java.util.Random; /* * Random:用于产生随机数 * * 使用步骤: * ...
- 关于php下的ajax赋值传值的调试
在tp中, 在js中也可以使用 模板变量替换(比如__PUBLIC__)和 模板函数调用(比如: {:U('..')}) 等. 但是 只有直接放在 相应的 模板文件中, 只有放在index.html之 ...
- 阿里云盾SSL证书即将到期怎么办?
如果你也像我一样用了一个有效期限1年的DV证书,颁发厂商:Symantec.那当这个证书快到期的时候要怎么更换证书呢?1.证书安装环境是IIS82.下载重新购买的免费证书,对新证书进行重新先发.3.证 ...
- Visual Studio 2017/2019 企业版 Enterprise 激活码
VS2017 Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF VS2017 Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH ...
- python学习之旅(入门)
一.list 有序集合 1.list 有序集合 L = [95.5, 85, 59] 如L[1] = 85 ,L[-1] = 59 和php中array一个意思 用[] 表示就可以了 2.新增 ...
- scrapy爬虫具体案例步骤详细分析
scrapy爬虫具体案例详细分析 scrapy,它是一个整合了的爬虫框架, 有着非常健全的管理系统. 而且它也是分布式爬虫, 它的管理体系非常复杂. 但是特别高效.用途广泛,主要用于数据挖掘.检测以及 ...