HDU4762Cut the Cake(概率)

题目链接:

?pid=4762

题意:

将一个原型蛋糕分成m份扇形,,然后使n个草莓恰好在其中的一份上

分析:

我们从中先取出一个来有n种选择,然后剩下的n-1个草莓在其极角[0,360/m]的范围内。

一个的概率为1/m,n-1个的概率为1/m^(n-1);

因此总的概率为n/m^(n-1).,因为20^20超过了longlong, 需要用高精度

代码如下:

//package fuck;import java.math.BigInteger;import java.util.Scanner;public class Main {static BigInteger gcd(BigInteger a,BigInteger b){if(!b.equals(BigInteger.ZERO)) return gcd(b,a.mod(b));return a;}public static void main(String args[]){Scanner cin=new Scanner(System.in);int t = cin.nextInt();while(t>0){int m = cin.nextInt();int n = cin.nextInt();BigInteger N = BigInteger.valueOf(n);BigInteger M = BigInteger.valueOf(m).pow(n-1);BigInteger tmp = gcd(N,M);System.out.println(N.divide(tmp)+"/"+M.divide(tmp));t–;}} }

有些人注定是等待别人的,有些人是注定被人等的。

HDU4762Cut the Cake(概率)

相关文章:

你感兴趣的文章:

标签云: