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 ...
随机推荐
- [参考]ASCII对照表 及 字符与二进制、十进制、16进制之间的转化(C/C++)
第1节 ASCII码对照表 1.1 ASCII控制字符 1.2 ASCII可显示字符 第2节字符的进制转换 2.1 获取字符(8位)的上四位和下四位 2.2 获取字符(上表中的‘图形’)所对应的十六进 ...
- 一些常用的JavaScript正则表达式
1.正数,最多n位小数 /^(([1-9]\d*(\.\d{1,n})?)|(0\.\d{1,n}))$/ 2.手机号码 /^1[34578]\d{9}$/
- pybedtools --bedtools的python包
http://daler.github.io/pybedtools/ 用个下面这个 >>> fn = pybedtools.example_filename('test.fa') & ...
- 读书笔记:提高C++性能的编程技术
Efficient C++ Performance Programming Techniques 第1章 跟踪范例 1.1 关注点 本章引入的实际问题为:定义一个简单的Trace类,将当前函数名输出到 ...
- [osgearth]oe学习的一些经验(别人的)
参考:http://bbs.osgchina.org/forum.php?mod=viewthread&tid=5484&extra=page%3D1&_dsign=70b15 ...
- Hive 建外链表到 Hbase(分内部表、外部表两种方式)
一. Hive 建内部表,链到hbase :特点:Hive drop表后,Hbase 表同步删除 drop table if exists hbase_kimbo_test1;CREATE TABLE ...
- data模块
这个模块原本应该存放Excel文件,提供utils目录下的config模块调用: 这里公司内部无法使用Excel读取数据,顾使用了ddt,其实里面就是.xslx文件
- telent服务搭建并远程连接
一.Telnet协议 Telnet协议是TCP/IP协议族中的一种,在网络层协议中它属于应用层协议,是Internet远程登陆服务的标准协议.可以使用本地计算机远程连接服务器,从而能够把本地用户所使用 ...
- 2018HN多校
http://acm.hi-54.com/contest_problemset.php?cid=1455 A : 摩斯密码 概览问题列表状态排名 Progress Bar 时间限制:1 Sec 内存限 ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...