Cut the Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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)
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这个题目的式子是(N*M)/(M^N)但是比较大数,所以java搞定,话说java API真是给力啊!!!!package acm; import java.util.*; import java.math.*; public class Main { public static void main(String[]args) { Scanner br=new Scanner(System.in); int t=br.nextInt(); while(t>0) { t--; String m=br.next(); String n=br.next(); BigInteger a=new BigInteger(m); BigInteger b=new BigInteger(n); a=a.pow(Integer.parseInt(n)-1); BigInteger d=a.gcd(b); System.out.println(b.divide(d) + "/" + a.divide(d)); } } }
本文介绍了一道关于计算特定条件下获取所有草莓概率的问题。通过分析蛋糕被等份切割后的可能性,利用Java的大数处理能力,实现了准确的概率计算并以最简分数形式输出。
1136

被折叠的 条评论
为什么被折叠?



