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. Objective-C:MRC手动释放对象内存举例(引用计数器)

    手机内存下的类的设计练习: 设计Book类, 1.三个成员变量:    title(书名)author(作者).price(价格) 2.不使用@property,自己完成存取方法(set方法,get方 ...

  2. 第一章 Java代码执行流程

    说明:本文主要参考自<分布式Java应用:基础与实践> 1.Java代码执行流程 第一步:*.java-->*.class(编译期) 第二步:从*.class文件将其中的内容加载到内 ...

  3. scala 学习笔记十 一 伴生对象

    1.介绍 a.所谓伴生对象就是和某个class同名的object, 并且object 必须和class在同一个scala源文件中. b.在scala中,没有像java中的静态类,静态方法和静态成员等, ...

  4. Nginx配置文件(nginx.conf)配置具体解释

    欢迎扫码增加Java高知群交流 Nginx的配置文件nginx.conf配置具体解释例如以下:   user nginx nginx ; Nginx用户及组:用户 组. window下不指定   wo ...

  5. Redis自学笔记–Zset类型及管理简述

    Zset类型                                                                                               ...

  6. Oracle服务启动顺序导致ORA-12514

    在window 上装了oracle11g,按照常规步骤安装完成后一切OK,如下图所示 C:\Users\Administrator>sqlplus /nolog SQL*Plus: Releas ...

  7. Python基础语法学习整理

    1.基础 r’  ‘:原始字符串 pow.round是内建函数 2.序列通用操作: 索引:d[] 分片:[:] 相加:d+[] 乘法:[1,2]*3 成员判断:in 可用函数:len  max  mi ...

  8. wstring to wchar_t*

      If you want to convert from std::wstring to const WCHAR* (i.e. the returned pointer gives read-onl ...

  9. Java 强引用、 软引用、 弱引用、虚引用

     1.对象的强.软.弱和虚引用 在JDK 1.2曾经的版本号中.若一个对象不被不论什么变量引用,那么程序就无法再使用这个对象. 也就是说,仅仅有对象处于可触及(reachable)状态.程序才干使 ...

  10. 《Java程序设计》第16周周四:GUI编程及文件对话框的使用

    第一部分:实验项目  项目一:文件及选择 目的:了解文件对话框的用法,熟悉GUI中事件驱动的核心步骤. 1. 阅读博文 "JFileChooser (Java Swing提供的文件选择对话框 ...