HDU 4762 Cut the Cake(高精度)

Cut the Cake

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1657    Accepted Submission(s): 806


Problem Description
MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration). HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points.
 
Input
First line is the integer T, which means there are T cases.
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
 
Output
As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details.
 
Sample Input
2 3 3 3 4
 
Sample Output
1/3 4/27
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6263 6262 6261 6260 6259 
 

把n个草莓放到m块蛋糕上,问所有草莓在一起的概率

易推得公式:n/mn-1

 1 #include<stdio.h>  
 2 #include<string.h>  
 3 int s[50];  
 4 int gcd(int a,int b)  
 5 {  
 6     int d=a%b;  
 7     while(d)  
 8     {  
 9         a=b;  
10         b=d;  
11         d=a%b;  
12     }  
13     return b;  
14 }  
15 int main()  
16 {  
17     int t,m,n,i,j;  
18     scanf("%d",&t);  
19     while(t--)  
20     {  
21         scanf("%d%d",&m,&n);  
22         memset(s,0,sizeof(s));  
23         int num=s[0]=1;  
24         int a=n;  
25         for(i=1; i<n; i++)  
26         {  
27             int b=m,d=gcd(a,b);  
28             a/=d;  
29             b/=d;  
30             int c=0;  
31             for(j=0;j<num;j++)  
32             {  
33                 s[j]=s[j]*b+c;  
34                 c=s[j]/10;  
35                 s[j]%=10;  
36             }  
37             while(c)  
38             {  
39                 s[num++]=c%10;  
40                 c/=10;  
41             }  
42         }  
43         printf("%d/",a);  
44         for(i=num-1;i>=0;i--)  
45             printf("%d",s[i]);  
46         printf("
");  
47     }  
48     return 0;  
49 }
原文地址:https://www.cnblogs.com/caiyishuai/p/13271210.html