Lottery

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3333    Accepted Submission(s): 1489

Problem Description
Eddy's
company publishes a kind of lottery.This set of lottery which are
numbered 1 to n, and a set of one of each is required for a prize .With
one number per lottery, how many lottery on average are required to make
a complete set of n coupons?
 
Input
Input
consists of a sequence of lines each containing a single positive
integer n, 1<=n<=22, giving the size of the set of coupons.
 
Output
For
each input line, output the average number of lottery required to
collect the complete set of n 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 ouput.
 
Sample Input
2
5
17
 
Sample Output
3
5
11 --
12
340463
58 ------
720720
 
Author
eddy
题意很难理解。。看了别人的翻译才懂。。
题目的大概意思是说一套彩票有编号1到n共n种,张数不限,问你平均买多少张能把编号为1到n的n中彩票全买下来,也就是求期望。
也就是求n/n+n/(n-1)+...+n/1..迭代求解 a/b+1/i = ai+b/(bi)
第一组测试用例后面明明有一个空格...结果加了之后还报了一次格式错误。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
int getLen(LL num){
int ans = ;
while(num){
ans++;
num/=;
}
return ans;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
LL a=,b=; ///a为分子,b为分母
for(int i=;i<=n;i++){
a = a*i+b;
b = b*i;
LL d = gcd(a,b);
a/=d;
b/=d;
}
a=a*n;
LL d = gcd(a,b);
a/=d,b/=d;
LL res = a/b;
if(a%b==){
printf("%lld\n",a/b);
}else {
LL len = getLen(res);
LL len1 = getLen(b);
LL yushu = a%b;
for(int i=;i<=len;i++){
printf(" ");
}
printf("%lld\n%lld ",yushu,res);
for(int i=;i<len1;i++) printf("-");
printf("\n");
for(int i=;i<=len;i++){
printf(" ");
}
printf("%lld\n",b);
}
}
return ;
}

hdu 1099(数学)的更多相关文章

  1. hdu 1099 Lottery

    这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客. HDU 1099 Lottery Time Limit: 2000/1000 MS (Java/Others)     ...

  2. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  3. HDU 1099 Lottery (求数学期望)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others)   ...

  4. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  5. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  6. *HDU 2451 数学

    Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  7. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  8. hdu 4506(数学,循环节+快速幂)

    小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  9. hdu 4432 数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了.在坚持几天然后ACM退役 ...

随机推荐

  1. 洛谷 P3328 【[SDOI2015]音质检测】

    这题我做的好麻烦啊... 一开始想分块来着,后来发现可以直接线段树 首先考虑一个性质,我们如果有数列的相邻两项f[i]和 f[i+1]那么用这两项向后推k项其线性表示系数一定(表示为f[i+k]=a∗ ...

  2. C#基础-数组

    数组定义 定义数组并赋值 int[] scores = { 45, 56, 78, 98, 100 }; //在定义数组时赋值 for(int i = 0; i < scores.Length; ...

  3. vue.js笔记1.0

    事件: 事件冒泡行为: 1.@click="show($event)" show:function (ev) { ev.cancelBubble=true; } 2.@click. ...

  4. 树莓派开发板入门学习笔记2:[转]树莓派系统在VM中能做什么

    问"树莓派系统在VM中能做什么"不如问"树莓派能做什么":(参考:树莓派实验室) 普通难度的DIY 较高难度的DIY 用树莓派打造一个家庭影院 给树莓派安装摄像 ...

  5. Linux对大容量硬盘分区

    随着单块硬盘容量的增大和硬盘价格的下降,2TB的磁盘使用将很快会普及,由于传统的MBR方式存储分区表的方 式缺陷,将可能导致很多分区工具不能正确地读取大于2TB容量的硬盘而无法正常分区大容量硬盘.其实 ...

  6. Jenkins自动化搭建测试环境(二)

    Fork项目 找到项目 单击Fork 这时,会发送一个邮件到你的git邮箱中,点击链接即可完成fork 这样,这个工程就已经fork到自己的git上了 然后就可以下载这个工程到本机了 这里我们需要使用 ...

  7. SCOI 2010 滑雪

    题目描述 a180285非常喜欢滑雪.他来到一座雪山,这里分布着 MM 条供滑行的轨道和 NN 个轨道之间的交点(同时也是景点),而且每个景点都有一编号 ii ( 1 \le i \le N1≤i≤N ...

  8. 聊聊、Nginx GDB与MAIN

    上一篇文章主要介绍了 Nginx 在 Window 和 Linux 平台上的安装.本章节主要介绍 Nginx 源码学习方法和源码结构,以及 Nginx 启动时 main 方法的位置,参数信息.后面的章 ...

  9. [uiautomator篇][python调用java][1]应用下载的插件需要很长时间问题解决

    1第一次打开应用,可能会要求下载插件,我们先在/sdcard/Android/data/<packageName>  或者/data/data/<pakeageName>找到插 ...

  10. 安装anaconda并配置环境

    安装anaconda的步骤 1.确定系统信息 uname -a 2.下载对应版本 3.sh 安装shell脚本 4.添加到对应路径 5.安装完anaconda之后,创建虚拟环境 conda creat ...