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
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.
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 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.
3 3
3 4
4/27
把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(高精度)的更多相关文章
- 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 ...
- HDU 4762 Cut the Cake(公式)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
- 2013长春网赛1004 hdu 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...
- HDU 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...
- hdu 4762 Cut the Cake (大数乘法)
猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...
- HDU 4328 Cut the cake
Cut the cake Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdoj 4762 Cut the Cake
题意很简单就不说了. 解题的关键就是这个公式 answer=n/(m^(n-1)); 要用到大数的乘法.然后java水过. import java.util.*; import java.math.* ...
- HDU 2134 Cuts the cake
http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...
随机推荐
- mysql循环查询树状数据
完整function )) ) CHARSET utf8 BEGIN ) ; ) ; SET str = ''; SET cid =cast(rootId as CHAR); WHILE cid is ...
- mapply
相比 lapply( )和 sapply( )在一个向量上迭代,mapply( )可以在多个向量上进行迭代.换句话,mapply 是 sapply 的多元版本:mapply(function(a, b ...
- 3个方法实现JavaScript判断移动端及pc端访问不同的网站
3个方法比较简单,分别在页面头部加入如下js代码: 对于简单地直接从www.maslinkcom跳转到m.maslink.com,此方法仅从首页而言: <script>(function ...
- 秒转为时分秒格式js
秒转为时分秒格式 function formatSeconds(value) { if(value == undefined) { value = 0; } var second = parseInt ...
- hdu 5303 DP(离散化,环形)+贪心
题目无法正常粘贴,地址:http://acm.hdu.edu.cn/showproblem.php?pid=5303 大意是给出一个环形公路,和它的长度,给出若干颗果树的位置以及树上的果子个数. 起点 ...
- UVA-127 "Accordian" Patience (模拟)
题目大意:一种纸牌游戏,将52张扑克牌排成一列,每次操作可将一张扑克牌移到它的前一张或前面第三张上当牌的点数或花色匹配时.每次都移动最靠左的扑克牌,并且能移动三格就移动三格.求最终扑克牌状态. 题目分 ...
- 牛客网——G大水题
链接:https://www.nowcoder.net/acm/contest/75/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- 在vue中使用scss的配置
1.创建一个基于 webpack 模板的新项目 $ vue init webpack myvue 2.在当前目录下,安装依赖 $ cd myvue$ npm install 3.安装sass的依赖包 ...
- Python+Flask+MysqL的web建设技术过程
一.前言(个人学期总结) 个人总结一下这学期对于Python+Flask+MysqL的web建设技术过程的学习体会,Flask小辣椒框架相对于其他框架而言,更加稳定,不会有莫名其妙的错误,容错性强,运 ...
- 联想A390T刷机ROOT教程
一.联想A390T手动进入Recovery的方法: [步骤一]首先,将你的A390T手机关机,关机状态下,先按住电源键2秒,不要松开,再同时按下音量加.音量减两个键,此时,3个键一直按住不要放开,几秒 ...