HDU 4762 Cut the Cake
来源:互联网 发布:菊次郎的夏天 知乎 编辑:程序博客网 时间:2024/05/23 02:04
Cut the Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 889 Accepted Submission(s): 436
Total Submission(s): 889 Accepted Submission(s): 436
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
23 33 4
Sample Output
1/34/27
Source
2013 ACM/ICPC Asia Regional Changchun Online
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4762
题目大意 :M个人分蛋糕,N个草莓随机分布在蛋糕上,把蛋糕平均分并优先选择一块,求你能拿到所有草莓的概率。
题目分析 :取最外面的一个草莓为第一刀切的位置,这样一共有N种方案,然后剩下N-1个草莓,每个的概率为1/M.所以概率为N / M ^ (N - 1)要求化简输出。
代码:
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4762
题目大意 :M个人分蛋糕,N个草莓随机分布在蛋糕上,把蛋糕平均分并优先选择一块,求你能拿到所有草莓的概率。
题目分析 :取最外面的一个草莓为第一刀切的位置,这样一共有N种方案,然后剩下N-1个草莓,每个的概率为1/M.所以概率为N / M ^ (N - 1)要求化简输出。
代码:
import java.util.Scanner;import java.math.*;public class Main{ static Scanner in = new Scanner(System.in); public static void main(String args[]) { int ca; BigInteger n, m, tmp; ca = in.nextInt(); while(ca-- != 0) { m = in.nextBigInteger(); n = in.nextBigInteger(); m = m.pow(n.intValue() - 1); tmp = m.gcd(n); System.out.println(n.divide(tmp) + "/" + m.divide(tmp)); } }}
0 0
- HDU 4762 Cut the Cake
- HDU-4762 Cut the Cake
- hdu 4762 - Cut the Cake(大数)
- hdu 4762 Cut the Cake(高精度&概率)
- hdu 4762 Cut the Cake(高精度)
- HDU 4328 - Cut the cake
- hdu 4328 Cut the cake
- hdu 4328 Cut the cake
- hdu 4328 Cut the cake
- HDU-4328-Cut the cake
- HDU 4328 Cut the cake
- hdu 4762 Cut the Cake(推导+高精度)
- HDU 4762 Cut the Cake(概率+推理+高精度)
- HDU 4762-Cut the Cake(概率+高精度)
- HDU 4762 Cut the Cake (高精度 + 公式)
- hdu 4762 Cut the Cake (概率 + java大数)
- HDu 4762 Cut the Cake 概率(推公式,积分)
- hdu - 4328 - Cut the cake - dp
- 螺旋矩阵求指定位置的数字
- Mybatis3中用log4j跟踪SQL语句
- 找工作笔试面试那些事儿(13)---操作系统常考知识点总结
- XCVBW444FGSCVDB XCV
- VGBHMFGHKTYUITYUITYU
- HDU 4762 Cut the Cake
- 拓扑排序算法的程序实现
- Storyboard入门到精通
- 64位Ubuntu中找不到arm-linux-gcc的解决办法
- 啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
- NYOJ 题目562盒子游戏(找规律,博弈)
- 分享一下如何检查系统是否支持Zend Optimizer的方法
- 单片机调试错误——仍在连接中, 请给MCU 上电...
- JavaSe基础XX20——网络编程