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. Postgres-XL的限制

    Postgres-XL是基于PostgreSQL的一个分布式数据库. 相比于PostgreSQL,XL的表的数据是可以分布到不同的datanode上的,对存在于不同的datanode上的数据进行处理, ...

  2. Bootstrap 模态框 select2搜索框无法输入

    去掉模态框的div中的 tabindex="-1" 这个属性 <div class="modal fade" role="dialog" ...

  3. mysql锁机制(转载)

    锁是计算机协调多个进程或线程并发访问某一资源的机制 .在数据库中,除传统的 计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所 ...

  4. jCarousel,jQuery下的滚动切换传送插件

    转自:http://www.zhangxinxu.com/jq/jcarousel_zh/#Examples 介绍 jCarousel是一款 jQuery 插件, 用来控制水平或垂直排列的列表项. 这 ...

  5. ccf 201803-1 跳一跳(Python实现)

    一.原题 问题描述 试题编号: 201803-1 试题名称: 跳一跳 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱. 简化 ...

  6. 【php】【趣味代码】对象引用的比较

    <?php $a = new stdClass(); $a->name = 'flint'; $b = $a ; $b->sex = 'man'; saveObject($b); f ...

  7. local search——配图

  8. Java技术——Java中创建对象的5种方式

    此文为译文 原文连接:https://dzone.com/articles/5-different-ways-to-create-objects-in-java-with-ex 0. 前言 作为Jav ...

  9. BZOJ 2217: [Poi2011]Lollipop

    若sum可行 sum-2一定可行 序列和为ans 找出和ans奇偶性不同的最大的ans,即最靠左或最靠右的1的位置 更新答案 有spj #include<cstdio> using nam ...

  10. Python之多线程与多进程(二)

    多进程 上一章:Python多线程与多进程(一) 由于GIL的存在,Python的多线程并没有实现真正的并行.因此,一些问题使用threading模块并不能解决 不过Python为并行提供了一个替代方 ...