题目链接: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. SQL连接查询的方式

    网上copy,以后来完整 连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件.WHERE和HAVING子句也可以包含搜索条件,以进一步筛选连接条件所选的行.          ...

  2. 【C++深入浅出】设计模式学习之观察者模式

    前言 前两天学习了weak_ptr以后还是不甚明了,一则需要实际应用去锤炼,二来就是不懂观察者模式. 正文 观察者模式又叫发布-订阅模式,定义了一种一对多的依赖关系,让多个观察者对象同时监听某一主题对 ...

  3. MyEclipse与Mysql数据库的连接

    1.载入MySql驱动程序 Class.forName("com.mysql.jdbc.Driver");    // 载入MySql驱动程序 2.建立Connection连接对象 ...

  4. Android 访问权限设置记录-存档留着有用!

    Android开发应用程序时,如果应用程序需要访问网络权限,需要在 AndroidManifest.xml 中加入以下代码: <uses-permission android:name=”and ...

  5. UIView上添加了一个按钮和一个单击手势的事件相应,互相不影响的处理方法。。

    tapGesture.delegate = self; - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shoul ...

  6. 函数组:FACS(FI/CO接口的FI服务)

    这个函数组可以执行与财务相关的各种检查,具体功能请自行发掘. 包含下列函数: ACC_ROUNDING_DIFF_DETERMINEACC_ROUNDING_DIFF_LINEITEMAC_KURSF ...

  7. Jordan Lecture Note-5: Kernels

    Kernels 我们首先来回顾kernel函数的定义:一个函数$K(x,y)$为kernel函数当且仅当对$\forall g, \int K(x,y)g(x)g(y)dxdy\geq 0$成立.另外 ...

  8. Android实现资料收藏

    1,调web浏览器 Uri myBlogUri = Uri.parse("http://xxxxx.com"); returnIt = new Intent(Intent.ACTI ...

  9. vb.net写的odbc连接dsn数据源和ole链接oracle的小例子

    最近由于工作需要开始接触vb2010,也叫vb.net.相比vb6.0有面向对象编程的优势.同时接触一门新语言,要更快的实际应用起来,链接数据库是必不可少的.之前用vba写过一个售书工具,正好可以拿来 ...

  10. ios快捷键

    分屏:cmd + option + return 退出分屏:cmd + return cmd + option + [ 代码上跳 cmd + [ 代码左移