Cut the Cake
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 586Accepted Submission(s): 283
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
Sample Output
Source
Recommend
liuyiding
题意:
随机在一块蛋糕上放n个草莓,然后用最好的方法切成m块相同大小形状的扇形,问你n个草莓在同一块蛋糕上面
的概率。
思路:
高中的组合公式。先考虑一个草莓。它放在一块蛋糕上的概率为(1/m)。剩下的草莓和它放一起的概率为(1/m)^(n-1)。将但将第一个草莓有n种可能。所以一块蛋糕上有全部草莓的概率为n/(m^n)。但是蛋糕他可以先选。所以。他得到全部草莓的概率应该是每一块蛋糕有全草莓概率的和。所以ans=n/(m^(n-1))。n和m的范围。需采用高精度做。
而Java高精度很方便所以就用Java了。第一份Java代码。嘿嘿。
详细见代码:
import java.util.Scanner;
import java.math.*;
public class Main {
static Scanner cin=new Scanner(System.in);
public static void main(String args[])
{
int t;
BigInteger n,m,gc;
t=cin.nextInt();
while(t--!=0)
{
m=cin.nextBigInteger();
n=cin.nextBigInteger();
m=m.pow(n.intValue()-1);
gc=m.gcd(n);
System.out.println(n.divide(gc)+"/"+m.divide(gc));
}
}
}
分享到:
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
记不得是pku还是hdu的代码了,题号是1906和1965!关于高精度的,对于ACM的爱好者来说,高精度是基础!
hdu2101AC代码
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu1290 解题报告 献给杭电五十周年校庆的礼物 (切西瓜问题,即平面分割空间)
hdu 1166线段树代码
ACM HDU题目分类,我自己总结的大概只有十来个吧
自己做的HDU ACM已经AC的题目
HDU最全ac代码
hdu动态规划算法集锦
hdu题目分类