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. openshift 添加cron定时任务

    一般linux添加cron任务是在/etc/crontab,但是由于openshift的权限木有这么开放,所以如果需要设置定时任务的话,需要在如下的文件夹下添加你的sh文件,因为我需要的是每天运行一次 ...

  2. 列出Windows域中所有的机器

    我所在的部门大概管理了300+台Windows终端,最近开始采用域的方式来进行管理.(别笑我们土,原来手工修改Windows口令太痛苦了.) 现在的任务是想在域控服务器中列出纳入域管理的所有机器,以及 ...

  3. 深度学习材料:从感知机到深度网络A Deep Learning Tutorial: From Perceptrons to Deep Networks

    In recent years, there’s been a resurgence in the field of Artificial Intelligence. It’s spread beyo ...

  4. RuntimeError: Working outside of application context.

    flask执行错误: 问题:RuntimeError: Working outside of application context. 方法: from flask import Flask, cur ...

  5. 数学图形之将曲线(curve)转化成曲面管

    在我关于数学图形的博客中,一开始讲曲线的生成算法.然后在最近的章节中介绍了圆环,还介绍了螺旋管以及海螺的生成算法.一类是曲线,一类是环面,为什么不将曲线变成环的图形,毕竟曲线看上去太单薄了,这一节我将 ...

  6. pat 1060 比较科学计数法

    trick: 1.前导0 如:000001,000.000001 2.出现0时也要按照科学计数法输出 e.g. 4 00000.00000 0001 NO 0.0000*10^0 0.1*10^1 3 ...

  7. Binary Tree Preorder Traversal leetcode java

    题目: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given bina ...

  8. 基于json的jquery地区联动探索

    贴一个基于jquery联动的代码,相信这样的代码有一大把,就当是jquery的练手吧, 写这个东西的初衷是来之于新浪微博,在新浪微博帐号设置里面有个地区的选项,使用js写的,想把它的代码给截获下来,可 ...

  9. CSS3中background属性的调整

    CSS3对于background做了一些修改,最明显的一个就是采用设置多背景,不但添加了4个新属性,并且还对目前的属性进行了调整增强. 1.多个背景图片 在css3里面,你可以再一个标签元素里应用多个 ...

  10. IOS 设置圆角用户头像

    在App中有一个常见的功能,从系统相册或者打开照相机得到一张图片,然后作为用户的头像.从相册中选取的图片明明都是矩形的图片,但是展示到界面上却变成圆形图片,这个神奇的效果是如何实现的呢? 请大家跟着下 ...