HDUOJ 1099——Lottery
2013-09-04 10:30
351 查看
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2061 Accepted Submission(s): 941[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
5
17
[align=left]Sample Output[/align]
3
5
11 --
12
340463
58 ------
720720
[align=left]Author[/align]
eddy
[align=left]Recommend[/align]
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==0) 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[20]={'\0'},num[20]={'\0'}; _int64 a,b,c,real; while(scanf("%d",&n)!=EOF) { a=b=1; for(i=2;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,10); itoa(real,num,10); for(i=0;i<=strlen(num);i++) printf(" "); printf("%I64d\n%I64d ",a,real); for(i=0;i<strlen(str);i++) printf("-"); puts(""); for(i=0;i<=strlen(num);i++) printf(" "); printf("%I64d\n",b); } else printf("%I64d\n",n*a/b); } return 0; }
View Code
相关文章推荐
- HDU 1099 Lottery (数学问题模拟)
- hdu 1099 Lottery 解题分析
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdoj1099 Lottery(简单的数学问题变相考察最小公倍数)
- hdu 1099 Lottery
- hdu 1099 Lottery
- 杭电1099_Lottery——java
- hdoj 1099 Lottery(期望)
- hdu1099 lottery 假分式 字符串函数 strncpy sprintf 函数 数字输入字符数组 公约数
- HDU—— 1099 Lottery
- HDU 1099 Lottery
- HDU/HDOJ 1099 Lottery
- HDOJ 1099 Lottery
- hdu 1099 lottery
- 【HDOJ】1099 Lottery
- HDOJ HDU 1099 Lottery
- 杭电1099——Lottery(关于__int64的使用详解)
- HZAU 1099 Die Die Die!(分类讨论水题)
- 1099任务执行顺序(贪心算法)