这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客。

HDU 1099

Lottery

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

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

 
题目的大概意思是说一套彩票有编号1到n共n种,张数不限,问你平均买多少张能把编号为1到n的n中彩票全买下来,也就是求期望。
举个例子,当n=5时,第一张有用的概率为1,买一张就行了,第二张有用的概率为4/5,所以买5/4张彩票能买上对你有用的,一次类推,sum=1+5/4+5/3+5/2+5/1=11…5/12,再有就是注意格式
附上我的AC代码

#include <iostream>
using namespace std; int n,s,a1,b1,a2,b2,s1,s2;
int gcd(int x,int y)
{
int t;
while (x%y!=0)
{
t=x%y;
x=y;
y=t;
}
return y;
}
int f(int x,int y)
{
int t1=a1,t2=b1;
a1=t1*y+b1*x;
b1=t2*y;
int t=a1/b1;
s+=t;
a1-=t*b1;
t=gcd(a1,b1);
a1=a1/t;
b1=b1/t;
}
int main()
{
while (cin>>n)
{
s=0;
a1=0;b1=1;
for (int i=1;i<=n;i++)
{
f(n,i);
}
if (a1==0)
cout <<s<<endl;//" "<<a1<<" "<<b1<<endl;
else
{
int t1=0,t2=0,temp1=s,temp2=b1;
while (temp1!=0)
{
t1++;
temp1/=10;
}
t1++;
while (temp2!=0)
{
t2++;
temp2/=10;
}
for (int i=1;i<=t1;i++)
cout <<" ";
cout <<a1<<endl;
cout <<s<<" ";
for (int i=t2;i>=1;i--)
cout <<"-";
cout <<endl;
for (int i=1;i<=t1;i++)
cout <<" ";
cout <<b1<<endl;
}
}
return 0;
}

hdu 1099 Lottery的更多相关文章

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

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

  2. HDU - 1099 - Lottery - 概率dp

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

  3. 1099 Lottery

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

  4. HDUOJ 1099——Lottery

    Lottery Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  5. hdu 1099(数学)

    Lottery Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  6. 【HDOJ】1099 Lottery

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

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

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

  8. HDU1099---数学 | 思维

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

  9. HDU 2985 Another lottery(坑题)

    点我看题目 题意 : 有n个人,每个人可以玩m轮,每一轮中每个参与者都有cj张票,第 i 轮的奖金是2的i次方,问你每个人所能赢得最多的奖金的概率是多少. 思路 : 这个题比较坑啊,其实不用去算前几轮 ...

随机推荐

  1. 解决Sublime-Text-3在ubuntu下中文输入的问题

    在ubuntu下使用ST这神器已经一段日子了,但是一直有个纠结的问题,就是中文输入非常坑爹,曾经一段时间,使用inputHelper这个插件来解决, 但是……每次都要按个快捷键,弹出一个小小小框来输入 ...

  2. Python 学习日记(第三周)

    知识回顾 在上一周的学习里,我学习了一些学习Python的基础知识下面先简短的回顾一些: 1Python的版本和和安装 Python的版本主要有2.x和3.x两个版本这两个版本在语法等方面有一定的区别 ...

  3. Service Lane

    Link https://www.hackerrank.com/challenges/service-lane def main(): n, t = map(int, raw_input().spli ...

  4. [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product

    Problem A. Minimum Scalar Product   This contest is open for practice. You can try every problem as ...

  5. BZOJ 1497 最大获利(最大权闭合子图)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1497 思路:由题意可以得知,每个顾客都依赖2个中转站,那么让中转站连有向边到汇点,流量为它的建设费用 ...

  6. Visual studio 使用正则表达查找替换

    原文 http://www.cnblogs.com/shineqiujuan/archive/2012/07/04/2575535.html 正则表达式是查找和替换文本模式的一种简洁而灵活的表示法.  ...

  7. linux xargs 使用

    xargs是一条Unix和类Unix操作系统的常用命令.它的作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题[1]. 例如,下面的命令: rm `find /path -type ...

  8. 7款纯CSS3实现的炫酷动画应用|慕课网只学有用的!

    关于我们 | 时尚廊 ♦ 时尚廊,中国大陆地区首家以"Lounge"为概念的艺文空间 ♦  7款纯CSS3实现的炫酷动画应用|慕课网只学有用的! 7款纯CSS3实现的炫酷动画应用

  9. 程序员求职之道(《程序员面试笔试宝典》)之求职有用网站及QQ群一览表

    技术学习网站 www.csdn.com www.iteye.com www.51cto.com http://www.cnblogs.com/ http://oj.leetcode.com/ http ...

  10. FFmpeg缩放swscale详解 <转>

    利用ffmpeg进行图像数据格式的转换以及图片的缩放应用中,主要用到了swscale.h文件中的三个函数,分别是: struct SwsContext *sws_getContext(int srcW ...