HDU 1099 Lottery

Lottery

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

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 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,i,j,a,b,c;
 7     int fz[23]={0},fm[23]={0},zs[23]={0};
 8     int sum=1, gbs=1;
 9     zs[1]=1;
10     for(i=2; i<=22; i++)
11     {
12         for(j=1; j<=i; j++)
13         {
14             if(j*gbs%i==0)
15             {
16                 gbs=j*gbs;
17                 sum=j*sum+gbs/i;
18                 fm[i]=gbs/i;
19                 zs[i]=sum/fm[i];
20                 fz[i]=sum%fm[i];
21                 a=fm[i];
22                 b=fz[i];
23                 while(b!=0)
24                 {
25                     c=a%b;
26                     a=b;
27                     b=c;
28                 }
29                 fz[i]=fz[i]/a;
30                 fm[i]=fm[i]/a;
31                 break;
32             }
33         }
34     }
35     while(cin>>i)
36     {
37         if(fz[i])
38         {
39             int lin=zs[i], len=2, num=1;
40             while(lin/10)
41             {
42                 lin/=10;
43                 len++;
44             }
45             lin=fm[i];
46             while(lin/10)
47             {
48                 lin/=10;
49                 num++;
50             }
51             cout<<string(len, ‘ ‘)<<fz[i]<<endl;
52             cout<<zs[i]<<‘ ‘<<string(num, ‘-‘)<<endl;
53             cout<<string(len, ‘ ‘)<<fm[i]<<endl;
54         }
55         else
56         {
57             cout<<zs[i]<<endl;
58         }
59     }
60     return 0;
61 }

原文地址:https://www.cnblogs.com/zhaopeng938/p/9418703.html

时间: 2024-10-18 02:34:33

HDU 1099 Lottery的相关文章

HDU 1099 [Lottery] 数学期望

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1099 题目大意:一套卡片有n张,每次购买随机获得一张卡片,问集齐一套卡片的期望次数是多少? 关键思想:知道此处期望是概率的倒数即可,比如有5张卡片, 第一步你获得想要卡片的概率是1,倒数为1: 第二步你获得想要卡片的概率是4/5,倒数为5/4: 第三步你获得想要卡片的概率是3/5,倒数为5/3: --累加即为结果,格式输出有些坑爹,耐心就好. 代码如下: #include <iostream> u

HDU - 1099 - Lottery - 概率dp

http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[n]=0,因为我们已经集齐了. \[dp[i]=(\frac{i}{n}*dp[i]+\frac{n-i}{n}*dp[i+1])+1\] 移项得答案. 然后写个分数类,注意约分. #include<bits/stdc++.h> using namespace std; typedef long

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

HDU ACM 1099 Lottery

题意:n种彩票,要想集齐这所有的n种,需要买多少张彩票 分析:n种,要求的结果就是n/n + n/n-1 + n/n-2 +...+ n/2 + n/1 ,即n*(1/n + 1/n-1 +...+ 1/2 +1/1).要集齐n种不同的彩票,买第一张任意,概率为n/n,买第二张需要和第一张不同,即剩下n-1种里哪种都可以,成功概率是n-1/n...如果已经集齐了n-1种,由于是均匀分布的,所以买到最后一种彩票的概率是1/n.从期望的角度来说我们需要买n张,才能买到.同理,当拥有一半种类的彩票时,

hdu 1099(数学)

Lottery Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3333    Accepted Submission(s): 1489 Problem Description Eddy's company publishes a kind of lottery.This set of lottery which are numbered

HDU1099---数学 | 思维

hdu 1099 Lottery题意:1~n编号的彩票,要买全,等概率条件下平均要买几张.已经买了m张时,买中剩下的概率为1-m/n,则要买的张数为1/(1-m/n)n=2,s=1+1/(1-1/2);n=3,s=1+1/(1-1/3)+1/(1-2/3)s=1+1/(1-1/n)+1/(1-2/n)+1/(1-3/n)+--+1/(1-(n-1)/n)=n/n+n/(n-1)+n/(n-2)+--+n/1=sum(n/i),i=1~nb/a+d/c=(bc+ad)/(ac)然后递推着通分,化简

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

HDU 3105 Fred&#39;s Lotto Tickets(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3105 Problem Description Fred likes to play the lotto. Whenever he does, he buys lots of tickets. Each ticket has 6 unique numbers in the range from 1 to 49, inclusive. Fred likes to ``Cover all his base

HDU 5087 (线性DP+次大LIS)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目大意:求次大LIS的长度.注意两个长度相同的LIS大小比较,下标和大的LIS较大. 解题思路: 结构体记录当前点的最大长fir,次长sec. 对于f[i].fir的转移,其实就是裸的LIS. 只不过当f[j].fir+1>=f[i].fir的时候也要转移,这时候尽管两个LIS长度相等,但是大小不一样. 对于f[i].sec的转移,首先它的初始值是0,在a[i]>a[j]条件下: ①首先