HDU-4762 Cut the Cake
来源:互联网 发布:java 实现 ping ip 编辑:程序博客网 时间:2024/06/05 17:00
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=4762题意:
一个蛋糕上随机放n个草莓,蛋糕要切成m份,每份大小形状完全一样。求小明先选的那块蛋糕上有所有草莓的概率。思路:
就是推公式加高精度。
首先以其中一个草莓为标准,就有n种可能,其他草莓在这个草莓所在那块的概率是1/m。
总的概率就是 n*(m^(n-1)).
然后直接高精度求解即可。
然而对于我来说到这里才懵了,,毕竟java不熟,,大数模版套过来还要求gcd化简分数,写出来真真是累。
于是还是老老实实去又学了学java的高精度。
代码:
import java.io.PrintWriter;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 n,m; BigInteger a,b,c; int T = cin.nextInt(); while(T>0) { T--; m = cin.nextInt(); n = cin.nextInt(); a = BigInteger.valueOf(m); b = BigInteger.valueOf(n); a = a.pow(n-1); c = gcd(a,b); System.out.println(b.divide(c)+"/"+a.divide(c)); } }}
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
- Python多进程编程
- c/c++ 取得当前目录
- android studio 导入源码
- 第五周第三天
- 更新表所有id的存储过程
- HDU-4762 Cut the Cake
- A,B两个整数集合,设计一个算法求他们的交集,尽可能的高效(牛客网)
- Socks协议
- Product of Array Except Self
- Spark-1.4.0单机部署(Hadoop-2.6.0采用伪分布式)【已测】
- Linux下如何搭建WEB服务器教程(apach)
- Python多进程编程
- MYSQL 字符集 & 校验规则
- 【HDU1698】【线段树成段更新】