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 ...
随机推荐
- luogu p1101 单词方阵
https://www.luogu.org/problem/show?pid=1101 很恶心的代码 就是八个方向都搜索 #include<bits/stdc++.h> using na ...
- QWebEngineView_简单例子_01
工程名 : WebEngine01 1.WebEngine01.pro #------------------------------------------------- # # Project c ...
- nodejs项目的model操作mongo
想想以前学习hibernate的时候,学习各种表和表之间的映射关系等一对多,多对一,多对多,后来到了工作中,勇哥告诉我, 那时在学习的时候,公司中都直接用外键关联. 这里我们学习下,如何在Nodejs ...
- angular 自定义指令参数详解
restrict:指令在dom中的声明形式 E(元素)A(属性)C(类名)M(注释) priority优先级:一个元素上存在两个指令,来决定那个指令被优先执行 terminal:true或false, ...
- Ubuntu 16.04 日常工具
shutter sudo apt-get install shutter indicator-sysmonitor 之前需要通过deb包安装,现在可以通过添加PPA安装: sudo add-apt-r ...
- PHP获取访客IP、地区位置信息、浏览器、来源页面
不多说了,每个方法都注释了,可以直接用: <?php //这个类似用来获取访客信息的 //方便统计 class visitorInfo { //获取访客ip public function ge ...
- Total Defense Anti-Virus – 免费6个月
Total Defense Anti-Virus 具有病毒和间谍软件保护,免费的专家远程安装和设置,快速扫描引擎不会拖慢电脑速度,基于云保护.高级Rootkit保护,自动扫描驱动器和内存等等.官方网站 ...
- WebLogic发布S2SH应用时提示ClassNotFoundException: org.hibernate.hql.ast.HqlToken异常
使用Spring+hibernate如下 <properties> <!--定义方言.fetch深度.是否显示sql--> <property name="hi ...
- Beta阶段第1周/共2周 Scrum立会报告+燃尽图 02
作业要求与 [https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284] 相同 版本控制:https://git.coding.net/li ...
- Winform开发之DataGridView事件和属性
DataDridView的事件和属性非常多,一一介绍还是不现实,这里借鉴一下园友和MSDN上的介绍吧 1.C#中 DataGridView 属性说明(转载) 2.MSDN上DataGridView事件 ...