题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762

题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋糕上的概率

Sample Input
2
3 3
3 4
 
Sample Output
1/3
4/27

分析:计算出这个概率公式为: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的更多相关文章

  1. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. 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 ...

  3. HDU 4762 Cut the Cake(高精度)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. hdu 4762 Cut the Cake概率公式

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...

  5. 2013长春网赛1004 hdu 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...

  6. hdu 4762 Cut the Cake (大数乘法)

    猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...

  7. HDU 4328 Cut the cake

    Cut the cake Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. hdoj 4762 Cut the Cake

    题意很简单就不说了. 解题的关键就是这个公式 answer=n/(m^(n-1)); 要用到大数的乘法.然后java水过. import java.util.*; import java.math.* ...

  9. HDU 2134 Cuts the cake

    http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...

随机推荐

  1. Oracle- 查询误删数据

    使用flashback table能恢复误删数据. flashback table CONTAINER_CONTENT to timestamp to_timestamp('2010-06-30 22 ...

  2. 原”zencart建站仿站俱乐部”现升级为”zencart 学院“!

    特别告示: 原”zencart建站仿站俱乐部”现升级为”zencart 学院“!

  3. 原生js操作cookie

    写cookie function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTim ...

  4. Sublime Text 3 安装插件管理 Package Control

    自动安装: 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴对应版本的代码后回车安装 适用于 Sublime Text 3: import   ...

  5. JFinal的Shiro权限管理插件--玛雅牛 / JFinalShiro

    http://git.oschina.net/myaniu/jfinalshiroplugin JFinalShiroPlugin JFinal的Shiro插件,实现权限管理. 升级说明 1)支持JF ...

  6. android的ListView做表格添加圆角边框

    边框,圆角,都可以实现的 在drawable目录下添加view_yuan_morelist.xml,设置控件的边框代码.如下: <?xml version="1.0" enc ...

  7. 使MySQL 支持繁体字

    要 MySQL 支持繁体字,可以将相关编码设置为 UTF8 (也叫 UTF-8).编码的设置从浏览器到表字段,一个都不能少: 浏览器设置 HTML设置 服务器 Request 对象设置 数据库连接设置 ...

  8. 【甘道夫】HBase基本数据操作的详细说明【完整版,精绝】

    介绍 之前具体写了一篇HBase过滤器的文章.今天把基础的表和数据相关操作补上. 本文档參考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 全部代码均基于& ...

  9. Android 多点手势识别详解

    google 提供的API中,有个类,大家都很熟悉,GestureDetector.使用它,我们可以识别用户通常会用的手势.但是,这个类不支持多点触摸(可能 google认为没有人会在几个手指都在屏幕 ...

  10. Print2flash在.NET(C#)64位中的使用,即文档在线预览

    转:http://www.cnblogs.com/flowwind/p/3411106.html Print2flash在.NET(C#)中的使用,即文档在线预览   office文档(word,ex ...