HDU 4762 Cut the Cake (数学概率) 2013 ACM/ICPC 长春网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4762
题意:随机在一块蛋糕上放m个草莓,然后用最好的方法切成n块相同大小形状的扇形,问你m个草莓在同一块蛋糕上面的概率。
题解:以落在最左边的一颗来考虑,其余落在其右边概率为1/m^(n-1),考虑每一个都可能在最左,实际上就是乘以C(1,n)可以推出来概率公式为n / (m^(n-1))。然后用高精度就ok了,记得最后约分就行了。
AC代码:(Java)
import java.util.Scanner;import java.math.*;public class Main{static final int N=2010;static Scanner cin=new Scanner(System.in);static BigInteger one=BigInteger.ONE,zero=BigInteger.valueOf(0);static BigInteger xiaohao(BigInteger n,BigInteger m){BigInteger t;while(m.compareTo(zero)!=0){t=n.mod(m);n=m;m=t;}return n;}public static void main(String[] args){int T;int n;BigInteger m,gcd;T=cin.nextInt();while(T!=0){m=cin.nextBigInteger();n=cin.nextInt();BigInteger xh=one;for(int i=1;i<n;i++)xh=xh.multiply(m);gcd=xiaohao(xh,BigInteger.valueOf(n));xh=xh.divide(gcd);m=BigInteger.valueOf(n).divide(gcd);System.out.println(m+"/"+xh);T--;}}}