zoukankan      html  css  js  c++  java
  • HDU 4762 Cut the Cake(公式)

    Cut the Cake

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 263    Accepted Submission(s): 113


    Problem Description
    MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration). HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points.
     
    Input
    First line is the integer T, which means there are T cases.
    For each case, two integers M, N indicate the number of her friends and the number of strawberry.
    (2 < M, N <= 20, T <= 400)
     
    Output
    As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details.
     
    Sample Input
    2 3 3 3 4
     
    Sample Output
    1/3 4/27
     
    Source
     
    Recommend
    liuyiding
     

     公式为:n/m^(n-1)

    import java.util.Scanner;
    import java.math.BigInteger;
    
    public class Main{
        public static void main(String[] args){
            Scanner cin = new Scanner(System.in);
            int t = cin.nextInt();
            while(t!=0){
                t--;
                BigInteger m = cin.nextBigInteger();
                int n = cin.nextInt();
                BigInteger tmp=BigInteger.valueOf(n);
                BigInteger ans=m.pow(n-1);
                BigInteger x=ans.gcd(tmp);
                System.out.println(tmp.divide(x) + "/" + ans.divide(x));
            }
        }
    }
  • 相关阅读:
    界面间传值
    消息通知中心
    ios外部链接或者app唤起自己的app
    iOS跳转第三方应用举例一号店和京东
    ios 传递JSON串过去 前面多了个等号
    react-native 配置 在mac 上找不到.npmrc
    webView 获取内容高度不准确的原因是因为你设置了某个属性
    WKWebView 加载本地HTML随笔
    关于attibutedText输出中文字符后的英文和数字进行分开解析的问题
    iOS 企业包碰到的问题
  • 原文地址:https://www.cnblogs.com/twodog/p/12135342.html
Copyright © 2011-2022 走看看