hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762
题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率。
算法思路:n个草莓在圆形上有一个最左边的,为了好理解,先把假设草莓有1-n的不同编号。 现在从n个草莓中选出一个编号A的放在最左边(这个最左边可以随便放),得到C(n,1)*1.然后把其余的n-1草莓不分先后的放在A的右边角大小为(360)/m的扇形区域内就可以了。 所以概率为 n/(m^(n-1));
由于20^20超 long long了,所以要用高精度。而且要约分。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int GCD(int a,int b)
{
if(a < b) swap(a,b);
if(a % b == ) return b;
return GCD(b,a%b);
} int ans[],cnt; void BigIntergerMul(int n)
{
int b[],pv=; int temp = n;
while(temp)
{
b[++pv] = temp%;
temp /= ;
} if(cnt == )
{
for(int i=; i<=pv; i++)
{
ans[i] = b[i];
}
cnt = pv;
}
else
{
int c[],cnt1 = ;
memset(c,,sizeof(c)); for(int i=; i<=pv; i++)
{
for(int j=; j<=cnt; j++)
{
int mul = b[i]*ans[j];
int wei = j + i - ; c[wei] += mul; while(c[wei] >= ){
c[wei+] += c[wei]/;
c[wei] = c[wei]%;
wei++;
}
cnt1 = max(wei,cnt1);
}
}
cnt = max(cnt,cnt1);
for(int i=; i<=cnt; i++)
{
ans[i] = c[i];
}
} } int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
while(T--)
{
int M,N;
cin>>M>>N;
cnt = ;
memset(ansff,,sizeof(ans));
int fenzi = N;
for(int i=; i<N; i++)
{
int gcd = GCD(M,fenzi); //先分子与M约分,在用高精度相乘,这样不用最后两个高精度来约分。
fenzi = fenzi/gcd;
BigIntergerMul(M/gcd);
}
printf("%d/",fenzi);
for(int i=cnt; i>=; i--)
{
printf("%d",ans[i]);
}
printf("\n");
}
}
hdu 4762 Cut the Cake概率公式的更多相关文章
- 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 (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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...
- 2013长春网赛1004 hdu 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...
- 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 (大数乘法)
猜公式: 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 ...
随机推荐
- Oracle RAC OCR 和 VotingDisk 的备份与恢复
一:Voting DiskVoting Disk 这个文件主要用于记录节点成员状态,在出现脑裂时,决定那个Partion获得控制权,其他的Partion必须从集群中剔除.Voting disk使用的是 ...
- librarynotfoundforlPodsAFNetworking解决放案
http://www.it165.net/pro/html/201503/36422.html
- 利用CART算法建立分类回归树
常见的一种决策树算法是ID3,ID3的做法是每次选择当前最佳的特征来分割数据,并按照该特征所有可能取值来切分,也就是说,如果一个特征有四种取值,那么数据将被切分成4份,一旦按某特征切分后,该特征在之后 ...
- 授权(Authorization)
介绍 除了认证服务,laravel还提供了授权服务,laravel同样提供了一个简单的方式去组织授权的逻辑来控制资源的访问.我们提供了各种各样的方法协助你们组织授权的逻辑,这些都在下面的文档之中. 定 ...
- nau8822 codec driver 录音时mic bias 无法自动打开问题
nau8822 codec driver 录音时mic bias 无法自动打开问题 问题描述: kernel版本:3.10 在nuc970上测试nau8822驱动时发现,虽然驱动中有如下定义: SND ...
- Fizz Buzz
class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<st ...
- [转] 小tips: 使用 等空格实现最小成本中文对齐 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=4562 一.重见天日第 ...
- CentOS6.5 yum安装桌面环境
安装原因 安装centos6.5时选择了minimal CentOS最小化安装方式 需要使用浏览器拨号连接内网 安装过程 通过yum grouplist查询在 group 软件包中,Desktop.D ...
- jquery前端性能优化(持续添加。。。)
1.选择器的使用 (1)$('#id') 使用id来定位dom元素是性能最高的方法.jQuery底层将直接调用本地方法document.getElementById().如果id直接可以找到所要对 ...
- 【转】使用spring @Scheduled注解执行定时任务
http://blog.csdn.net/sd4000784/article/details/7745947 以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在s ...