Lottery

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

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
 
Recommend
JGShining
 

sum=n*∑(1/i);----->n*(1+1/2+1/3+.....+1/n);

题意不好懂.....表示看来白天没明白....之后看了别人的讲的题意才懂的.....

之后的就不难了!

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int gcd(_int64 a,_int64 b)
{
if(b==)
return a;
gcd(b,a%b);
}; void swap(_int64 *a,_int64 *b)
{
*a^=*b,
*b^=*a,
*a^=*b;
}
int main()
{
int n,i;
char str[]={'\0'},num[]={'\0'};
_int64 a,b,c,real;
while(scanf("%d",&n)!=EOF)
{
a=b=;
for(i=;i<=n;i++)
{
a=a*i+b;
b*=i;
if(a<b) swap(a,b);
c=gcd(a,b);
a/=c;
b/=c;
}
if((n*a)%b)
{
real=(a/b)*n;
a%=b;
a*=n;
real+=a/b;
a%=b;
c=gcd(a,b);
a/=c;
b/=c;
itoa(b,str,);
itoa(real,num,);
for(i=;i<=strlen(num);i++)
printf(" ");
printf("%I64d\n%I64d ",a,real);
for(i=;i<strlen(str);i++)
printf("-");
puts("");
for(i=;i<=strlen(num);i++)
printf(" ");
printf("%I64d\n",b);
}
else
printf("%I64d\n",n*a/b);
}
return ;
}

HDUOJ 1099——Lottery的更多相关文章

  1. hdu 1099 Lottery

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

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

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

  3. 1099 Lottery

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1099 英文水平太差了,题目实在是不知道是什么意思,然后看了其他高手写的思路,才看明白. 题意,收集n张彩票 ...

  4. HDU - 1099 - Lottery - 概率dp

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

  5. 【HDOJ】1099 Lottery

    题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. #include <cstdio ...

  6. 2018年暑假ACM个人训练题7 题解报告

    A:HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用) B:(还需要研究一下.....) C:HDU 1071 The area(求三个点确定的抛物线的面积, ...

  7. HDU1099---数学 | 思维

    hdu 1099 Lottery题意:1~n编号的彩票,要买全,等概率条件下平均要买几张.已经买了m张时,买中剩下的概率为1-m/n,则要买的张数为1/(1-m/n)n=2,s=1+1/(1-1/2) ...

  8. UVA10325 The Lottery(容斥原理)

    题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...

  9. 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;

     错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is:  java ...

随机推荐

  1. 局部敏感哈希 Kernelized Locality-Sensitive Hashing Page

    Kernelized Locality-Sensitive Hashing Page   Brian Kulis (1) and Kristen Grauman (2)(1) UC Berkeley ...

  2. vijos p1729 Knights

    描述 在一个N*N的正方形棋盘上,放置了一些骑士.我们将棋盘的行用1开始的N个自然数标记,将列用'A'开始的N个大写英文字母标记.举个例子来说,一个标准的8*8的国际象棋棋盘的行标记为1..8,列标记 ...

  3. 第二章 Javac编译原理

    注:本文主要记录自<深入分析java web技术内幕>"第四章 javac编译原理" 1.javac作用 将*.java源代码文件转化为*.class文件 2.编译流程 ...

  4. go语言基础之切片做函数参数

    1.切片做函数参数 (备注:用了冒泡排序) 示例: package main //必须有个main包 import "fmt" import "math/rand&quo ...

  5. TPC-E在populate测试Database时需要注意的一些事项

    第一,  安装时不要使用named instance, 默认的instance就好. 否则会报连不上Database. 第二, TPC-E工具文件夹的完整路径中不可以有空格, 否则会在generate ...

  6. 如何实现JS函数的重载

    javascript不能支持函数的重载,如下: function f(length) { alert("高为:"+length); } function f(length,widt ...

  7. Charles Proxy for Mac & Windows (4.1.3)破解激活工具

    1.简介 2017年7月10日更新本博客,Charles已经更新到了4.1.3版本,并对应地给出破解jar包. Charles是一个Mac和Windows平台都可以使用的抓包工具,它的破解激活非常简单 ...

  8. C#.NET常见问题(FAQ)-程序不包含适合于入口点的静态“Main”方法怎么办

    如下图所示,一般程序上次运行还好好的,而且不管你复制粘贴再简单的程序也出现这种错误提示.   先点击右侧的显示所有文件,下面列举了所有CS文件,右击点击包括在项目中,则该文件呈现绿色,再运行即可.不过 ...

  9. 织梦DeDeCms会员登录或退出跳转到首页的修改方法

    会员在主页登陆后,默认会跳转到会员中心,如果我们想登陆后,跳转到网站主页,那么就请参考下面的方法实现织梦DeDeCms会员登录或退出跳转到首页. 1.在根目录的member目录中找到index_do. ...

  10. IE 之 应用小结

    1. 导出收藏夹(IE11) 导出:打开浏览器, 文件(F) → 导入和导出(M)... → 导出到文件(E) → 指定导出内容 → 指定保存路径导入:打开浏览器,文件(F) → 导入和导出(M).. ...