HDU 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762
题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋糕上的概率
分析:计算出这个概率公式为:n/(mn-1),m、n最大为20,mn超出了64位,用到大数,用java容易写出
代码如下:
import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
int test=cin.nextInt();
while(test-->0)
{
BigInteger m;
m=cin.nextBigInteger();
int n=cin.nextInt();
m=m.pow(n-1);
BigInteger nn=BigInteger.valueOf(n);
BigInteger p=m.gcd(nn);
System.out.println(nn.divide(p)+"/"+m.divide(p));
}
}
}
HDU 4762 Cut the Cake的更多相关文章
- HDU 4762 Cut the Cake(公式)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake(高精度)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
- 2013长春网赛1004 hdu 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...
- hdu 4762 Cut the Cake (大数乘法)
猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...
- HDU 4328 Cut the cake
Cut the cake Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdoj 4762 Cut the Cake
题意很简单就不说了. 解题的关键就是这个公式 answer=n/(m^(n-1)); 要用到大数的乘法.然后java水过. import java.util.*; import java.math.* ...
- HDU 2134 Cuts the cake
http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...
随机推荐
- 避免SWF被内存提取工具提取的方法
内存工具从内存中抓取SWF一般是依靠寻找SWF的前7个字节(3个SWF文件必有的标示字节“FWS”或“CWS”或“ZWS”+4个记录该SWF文件长度的字节),所以避免被提取我们只要在加载SWF到内存后 ...
- 剑指OFFER之从1到n中出现1的次数(九度OJ1373)
题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他.问题是:求出1~13的整数中1出现的次数,并算出100~130 ...
- Android v4 包和v7包问题
昨天新建了一个android项目,加入了一个bootstrap的外部依赖和一个底部导航栏的外部依赖.结果jj 了,老是提醒我v4包v7包冲突: 事实是这样的,首先我的底部导航依赖库里面有一个v4包,那 ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- 使用Eclipse建立Maven的SpringMVC项目
非常感谢博客的大神,让我成功地构建项目 http://limingnihao.iteye.com/blog/830409 但在依照这篇文章构建构建时遇到了一些问题,在这里总结一下: 问题一.2.3.2 ...
- pomelo 开发环境搭建
开发前提条件: Windows系统,请确保你的Windows系统包括源代码编译工具.Node.js的源代码主要由C++代码和JavaScript代码构成,可是却用gyp工具来做源代码的项目管理,该工 ...
- GNU bash实现机制与源代码简析
http://www.cnblogs.com/napoleon_liu/archive/2011/04/01/2001886.html http://blog.csdn.net/ruglcc/arti ...
- eclipse+ADT 进行android应用签名详解
http://jojol-zhou.iteye.com/blog/719428 1.Eclipse工程中右键工程,弹出选项中选择 android工具-生成签名应用包: 2.选择需要打包的android ...
- multi-threads synchronization use conditional mutex
#include <pthread.h> int thread_flag; pthread_cond_t thread_flag_cv; pthread_mutex_t thread_fl ...
- Linux下Openssl的安装全过程
第一章 1.下载地址:http://www.openssl.org/source/ 下一个新版本的OpenSSL,我下的版本是:openssl-1.0.0e.tar.gz 可以通过#wget http ...