【HDOJ 4762】 Cut the Cake (数学概率+大数)
来源:互联网 发布:有声读书软件 编辑:程序博客网 时间:2024/05/29 04:06
【HDOJ 4762】 Cut the Cake (数学概率+大数)
Cut the Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1205 Accepted Submission(s): 581
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
n个草莓撒在蛋糕上 蛋糕分成m块 问草莓在同一块的概率
高中的不同球放不同盒子 球都在同一盒子的概率问题
先考虑第一颗草莓 放在某块蛋糕上的概率是1/m 其余n-1块草莓跟他在一起的概率是1/m^(n-1) 由于第一颗草莓可以选 所以*n 蛋糕也可以选 *m
化简就是 n/(m^(n-1)) 由于大数据是20 20 20^19会爆 所以上高精度 模板/JAVA
代码如下:
import java.util.*;import java.math.*;public class Main{public static void main(String[] args){Scanner in = new Scanner(System.in);BigInteger a,b,c;int n,m;int t=in.nextInt();while(t-->0){m=in.nextInt();n=in.nextInt();a=BigInteger.valueOf(n);b=BigInteger.valueOf(1);for(int i=1;i<n;i++)b=b.multiply(BigInteger.valueOf(m));BigInteger g=a.gcd(b);System.out.println(a.divide(g)+"/"+b.divide(g));}}}
0 0
- 【HDOJ 4762】 Cut the Cake (数学概率+大数)
- hdu 4762 Cut the Cake (概率 + java大数)
- HDOJ 4762 Cut the Cake(概率+Java)
- [概率]Cut the Cake
- hdu 4762 Cut the Cake(高精度&概率)
- hdu 4762 - Cut the Cake(大数)
- HDU 4762 Cut the Cake (数学概率) 2013 ACM/ICPC 长春网络赛
- Cut the Cake(大数)
- HDU 4762 Cut the Cake(概率+推理+高精度)
- HDU 4762-Cut the Cake(概率+高精度)
- HDu 4762 Cut the Cake 概率(推公式,积分)
- HDOJ 4762 - Cut the Cake 推公式.高精度
- HDU 4762 Cut the Cake
- HDU-4762 Cut the Cake
- hdu 4762 Cut the Cake 概率(2013 ACM/ICPC Asia Regional Changchun Online 1004)
- hdu 4762 Cut the Cake(高精度)
- hdu4762 Cut the Cake
- Cut The Cake
- UITabBar 【标签条】自己的见解
- mysql触发器编写
- 一点启迪
- 在OS X系统中php访问sftp时需要ssh2扩展的安装
- Android性能优化之界面UI篇
- 【HDOJ 4762】 Cut the Cake (数学概率+大数)
- Android Studio无法找到tool.jar解决方法!
- 模拟信号采样与AD转换
- Light oj 1031 Easy Game(记忆化)
- SQL Server 执行大数据量的sql文件
- LeetCode || N-Queens
- ubuntu14.04自定义系统默认xp字体
- 二十三种设计模式之创建型模式之建造者模式
- cgroup和LXC的安装