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): 1657    Accepted Submission(s): 806


    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   |   We have carefully selected several similar problems for you:  6263 6262 6261 6260 6259 
     

    把n个草莓放到m块蛋糕上,问所有草莓在一起的概率

    易推得公式:n/mn-1

     1 #include<stdio.h>  
     2 #include<string.h>  
     3 int s[50];  
     4 int gcd(int a,int b)  
     5 {  
     6     int d=a%b;  
     7     while(d)  
     8     {  
     9         a=b;  
    10         b=d;  
    11         d=a%b;  
    12     }  
    13     return b;  
    14 }  
    15 int main()  
    16 {  
    17     int t,m,n,i,j;  
    18     scanf("%d",&t);  
    19     while(t--)  
    20     {  
    21         scanf("%d%d",&m,&n);  
    22         memset(s,0,sizeof(s));  
    23         int num=s[0]=1;  
    24         int a=n;  
    25         for(i=1; i<n; i++)  
    26         {  
    27             int b=m,d=gcd(a,b);  
    28             a/=d;  
    29             b/=d;  
    30             int c=0;  
    31             for(j=0;j<num;j++)  
    32             {  
    33                 s[j]=s[j]*b+c;  
    34                 c=s[j]/10;  
    35                 s[j]%=10;  
    36             }  
    37             while(c)  
    38             {  
    39                 s[num++]=c%10;  
    40                 c/=10;  
    41             }  
    42         }  
    43         printf("%d/",a);  
    44         for(i=num-1;i>=0;i--)  
    45             printf("%d",s[i]);  
    46         printf("
    ");  
    47     }  
    48     return 0;  
    49 }
  • 相关阅读:
    UVA1401 Remember the word DP+Trie
    LG5202 「USACO2019JAN」Redistricting 动态规划+堆/单调队列优化
    模拟赛总结合集
    LG5201 「USACO2019JAN」Shortcut 最短路树
    LG5200 「USACO2019JAN」Sleepy Cow Sorting 树状数组
    LG5196 「USACO2019JAN」Cow Poetry 背包+乘法原理
    20190922 「HZOJ NOIP2019 Round #7」20190922模拟
    LG2530 「SHOI2001」化工厂装箱员 高维DP+记忆化搜索
    LG2893/POJ3666 「USACO2008FEB」Making the Grade 线性DP+决策集优化
    关于对QQ 输入法的评价
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/8448437.html
Copyright © 2011-2022 走看看