zoukankan      html  css  js  c++  java
  • HDU4762(JAVA大数)

    Cut the Cake

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


    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
    题意:切M块蛋糕,求N个草莓全部在一块蛋糕上的概率。
    公式:n/(m的n-1次方);
    收获:了解了下JAVA大数。化简可以用两个数的最小公倍数。
    import java.math.*;
    import java.util.*;
    public class Main {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner in = new Scanner(System.in);
            int t = in.nextInt();
            while(t-->0)
            {
                BigInteger m = in.nextBigInteger();
                int n = in.nextInt();
                m=m.pow(n-1); 
                BigInteger b=BigInteger.valueOf(n);
                BigInteger a;
                a = m.gcd(b);
                BigInteger c = m.divide(a);
                BigInteger c2 = b.divide(a);
                System.out.println(c2 + "/" + c);
            }
    
        }
    
    }
  • 相关阅读:
    容器镜像服务联手 IDE 插件,实现一键部署、持续集成与交付
    阿里巴巴大规模神龙裸金属 Kubernetes 集群运维实践
    4 个概念,1 个动作,让应用管理变得更简单
    从零开始入门 | Kubernetes 中的服务发现与负载均衡
    最佳实践 | 数据库迁云解决方案选型 & 流程全解析
    Thumbnail 图片帮助
    验证码-WebVcode
    访问者(Visitor)模式
    享元(Flyweight)模式
    中介者(Mediator)模式
  • 原文地址:https://www.cnblogs.com/ZP-Better/p/4734338.html
Copyright © 2011-2022 走看看