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

 #include<stdio.h>
#include<string.h>
int s[];
int gcd(int a,int b)
{
int d=a%b;
while(d)
{
a=b;
b=d;
d=a%b;
}
return b;
}
int main()
{
int t,m,n,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
memset(s,,sizeof(s));
int num=s[]=;
int a=n;
for(i=; i<n; i++)
{
int b=m,d=gcd(a,b);
a/=d;
b/=d;
int c=;
for(j=;j<num;j++)
{
s[j]=s[j]*b+c;
c=s[j]/;
s[j]%=;
}
while(c)
{
s[num++]=c%;
c/=;
}
}
printf("%d/",a);
for(i=num-;i>=;i--)
printf("%d",s[i]);
printf("\n");
}
return ;
}
上一篇:Socket TCP客户端和服务器的实现


下一篇:20175324 mycp