hdu 1099 lottery
来源:互联网 发布:天眼偷窥神器软件 编辑:程序博客网 时间:2024/05/01 06:26
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1086 Accepted Submission(s): 537
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
2517
Sample Output
3 511 -- 12 34046358 ------ 720720
Author
eddy
Recommend
JGShining
拿到第一张卡片的概率是 n/n ,期望次数是 1,拿到第二张的概率是 (n-1)/n, 期望次数是 n/(n-1) ...
把这些次数加起来 n/n + n/(n-1) + ... + n/1
don 分母 doneminator
num 分子 numerator
ws 空格 white space
ln 分数线 line
http://acm.hdu.edu.cn/forum/read.php?tid=16311&keyword=1099
#include <cstdlib>#include <cstdio>#include <cassert>#include <cstring>#include <algorithm>long long GCD (long long a, long long b) { if (b == 0) { return a; } return GCD (b, a % b);}int main () { long long n; while (scanf ("%lld", &n) == 1) { long long don = 1, num = 0; for (long long i=1; i<=n; ++i) { num = num * i + n * don; don = don * i; long long gcd = GCD (don, num); don = don / gcd; num = num / gcd; } if (num % don == 0) { printf ("%lld\n", num / don); } else { static char strInt[1024], strNum[1024], strDon[1024]; static char strWS[1024], strLn[1024]; static char ws[] = " "; static char ln[] = "------------------------------"; sprintf (strInt, "%lld", num / don); sprintf (strNum, "%lld", num % don); sprintf (strDon, "%lld", don); memset (strWS, 0, sizeof (strWS)); strncpy (strWS, ws, strlen (strInt)); memset (strLn, 0, sizeof (strLn)); strncpy (strLn, ln, std::max (strlen (strNum), strlen (strDon))); printf ("%s %s\n%s %s\n%s %s\n", strWS, strNum, strInt, strLn, strWS, strDon); } } return 0;}
- HDU/HDOJ 1099 Lottery
- hdu 1099 lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- 【数学】 HDU 1099 Lottery
- HDU ACM 1099 Lottery
- HDU 1099 Lottery 乐透彩
- HDOJ HDU 1099 Lottery
- hdu 1099 Lottery 解题分析
- HDU—— 1099 Lottery
- HDU 1099 Lottery (数学问题模拟)
- HDU 2985 Another lottery(水题)
- Lottery Hdoj 1099
- HDOJ 1099 Lottery
- Lottery
- hdoj 1099 Lottery(期望)
- Linux/ubuntu常用快捷键大集合
- stream故障处理汇总
- 类
- Android uevent
- Hadoop使用常见问题以及解决方法
- hdu 1099 lottery
- iphone学习笔记--获得iPhone通讯录中所有联系人的电话号码和邮箱
- Java 收取 和 发送 邮件+SSL
- How selection changed when select difference part in eclipse
- ABAP 报错了!!!啊!!!什么破语言!-----Statement is not accessible
- 储蓄理财5W原则
- 3.3 large class(过大的类)
- LISP的本质
- char varchar varchar2 的区别