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

 #include<stdio.h>
#include<string.h>
int s[];
int gcd(int a,int b)
{
int d=a%b;
while(d)
{
a=b;
b=d;
d=a%b;
}
return b;
}
int main()
{
int t,m,n,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
memset(s,,sizeof(s));
int num=s[]=;
int a=n;
for(i=; i<n; i++)
{
int b=m,d=gcd(a,b);
a/=d;
b/=d;
int c=;
for(j=;j<num;j++)
{
s[j]=s[j]*b+c;
c=s[j]/;
s[j]%=;
}
while(c)
{
s[num++]=c%;
c/=;
}
}
printf("%d/",a);
for(i=num-;i>=;i--)
printf("%d",s[i]);
printf("\n");
}
return ;
}

HDU 4762 Cut the Cake(高精度)的更多相关文章

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

  2. HDU 4762 Cut the Cake(公式)

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

  3. hdu 4762 Cut the Cake概率公式

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

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

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

  5. HDU 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...

  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. 利用IntelliJ IDEA创建第一个Groovy工程

    因为某些原因,需要学习一下Groovy.关于Groovy的入门教程请看这篇文章http://www.ibm.com/developerworks/cn/education/java/j-groovy/ ...

  2. [原][osgearth]osgearth本地(离线)数据源处理小结

    参考:http://docs.osgearth.org/en/latest/data.html Processing Local Source Data If you have geospatial ...

  3. Java回顾之ORM框架

    这篇文章里,我们主要讨论ORM框架,以及在使用上和JDBC的区别. 概述 ORM框架不是一个新话题,它已经流传了很多年.它的优点在于提供了概念性的.易于理解的数据模型,将数据库中的表和内存中的对象建立 ...

  4. C#中json字符串的序列化和反序列化

    改文章转自:https://www.cnblogs.com/shang201215019/p/7907655.html 什么是 Json ?        Json[javascript对象表示方法] ...

  5. Mybatis之SSM配置

    applicationContext-dao.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...

  6. mysql中InnoDB存储引擎的行锁和表锁

    Mysql的InnoDB存储引擎支持事务,默认是行锁.因为这个特性,所以数据库支持高并发,但是如果InnoDB更新数据的时候不是行锁,而是表锁的话,那么其并发性会大打折扣,而且也可能导致你的程序出错. ...

  7. Oracle Sourcing Implementation and Administration Guide(转)

    原文地址 Oracle Sourcing Implementation and Administration Guide

  8. [Java] Eclipse下导入外部jar包的3种方式

    我们在用Eclipse开发程序的时候,经常要用到第三方jar包.引入jar包不是一个小问题,由于jar包位置不清楚,而浪费时间.下面配图说明3种Eclipse引入jar包的方式.   1.最常用的普通 ...

  9. bzoj1037

    题解: 定义f[i][j][a][b]表示已经排了i个人 还能拍j个男的(那么就还有m-i+j个是女的) 还能连续拍a个男的,b个女的 我是递推的 考虑后面一个拍男的还是女的 注意要判断边界 代码: ...

  10. 在JavaScript中进行文件处理,第三部分:处理事件和错误

    译注:原文是<JavaScript高级程序设计>的作者Nicholas Zakas写的,本翻译纯属为自己学习而做,仅供参考.原文链接:这里 FileReader对象用来读取浏览器可以访问的 ...