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. Service Mesh是什么技术

    https://blog.csdn.net/weixin_38044696/article/details/80257488 Service Mesh是什么技术 2018年05月09日 22:07:4 ...

  2. 二分查找、upper_bound、lower_bound

    整理及总结二分查找的判断和边界细节 修改版 package com.leej.binarysearch; import java.util.Arrays; /** * @author jerry * ...

  3. linux关于进程、内存和cpu情况

    1.load average: 2.03, 1.76, 1.80 1分钟.5分钟.15分钟平均负载 2.%Cpu(s):100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa ...

  4. Python爬虫一

    爬虫 什么是爬虫? 网络爬虫(又被称为网页蜘蛛,网络机器人)就是模拟客户端发送网络请求,接收请求响应, 一种按照一定的规则,自动地抓取互联网信息的程序. 原则上,只要是浏览器(客户端)能做的事情,爬虫 ...

  5. python getopt模块使用方法

    python中 getopt 模块,是专门用来处理命令行参数的 getop标准格式: 函数getopt(args, shortopts, longopts = []) shortopts 是短参数   ...

  6. Django之cookie、session

    会话跟踪技术 可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应. 一次会话过程中,我们应该注意的是什么呢? 那就是,一些操作要保证用户操作的是用户自己个人的数据.举个 ...

  7. statistics-skewed data

    参考文献: http://www.statisticshowto.com/skewed-distribution/ left/negatively-skewed distributions : box ...

  8. ACM-ICPC 2017 Asia Urumqi A. Coins

    Alice and Bob are playing a simple game. They line up a row of n identical coins, all with the heads ...

  9. 实践自己的WebSite______流水

    尝试从头至尾搭建一个MVC的网站,主要以流水的方式进行进度和记录,而不讨论技术的部分. 1,在Controller下创建两个文件夹,分别为sys和Business,分别对应于系统功能和业务逻辑.比如登 ...

  10. selenium2断言类Assert的使用

    测试中断言的重要性 一.断言的作用: 1.断言也就是检查点,重在判断我们通过页面得出来的值与期望值是否相等,如果相等,则代表断言成功,程序会继续往下执行,如果不相等,则代表断言失败,程序就会在断言失败 ...