HDU4762Cut the Cake(概率)

题目链接:

http://acm.hdu.edu.cn/showproblem.php?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--;
        }
    }  
}  


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值