hdu 1099 Lottery
来源:互联网 发布:mac 文件夹无法移动 编辑:程序博客网 时间:2024/05/01 08:52
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1967 Accepted Submission(s): 898
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#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define ll long longclass Fen{ll a,b,z;public:Fen(ll i,ll j,ll k){a=i;b=j;z=k;}Fen operator+(const Fen &f){Fen t(0,0,0);t.z=z+f.z;t.b=b*f.b;t.a=a*f.b+b*f.a;t.to();return t;}void to(){//化简ll p=a,q=b,r;if(p<q)swap(p,q);while(q){r=p%q;p=q;q=r;}a/=p;b/=p;z+=a/b;a%=b;}void print(){//cout<<z<<" "<<a<<"/"<<b<<endl;if(a==0){cout<<z<<endl;return;}char s[30];sprintf(s,"%lld",z);int l=strlen(s),i;for(i=0;i<=l;i++)cout<<" ";cout<<a<<endl<<z<<" ";sprintf(s,"%lld",a);int L=strlen(s);sprintf(s,"%lld",b);i=strlen(s);for(i=max(i,L);i>0;i--)cout<<"-";cout<<endl;for(i=0;i<=l;i++)cout<<" ";cout<<b<<endl;}};//计算n*(1/1+1/2+..+1/n)int main(){int i,j,k,n;while(~scanf("%d",&n)){Fen a(0,1,n);for(i=2;i<=n;i++){Fen b(n,i,0);a=a+b;}a.print();}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(期望)
- C++实现反射
- ASP.NET—“Page”类
- char* a与char a[]的区别,const char* a与char* const a的区别
- How to host WPF Control into the Windows Form Application
- cortx-a8处理器可配置选项
- hdu 1099 Lottery
- 等宽瀑布流
- Document下创建文件.
- How to use .NET Windows Control into the WPF Application
- Unity发送参数给Android打开TestActivity0、TestActivity1
- 子查询中的NULL问题
- 10.android通讯录案例
- Send event to Host (Windows Form) from a WPF Control -Part 1
- 黑马程序员------三种文件读取模式