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 ...
随机推荐
- Ubuntu Server下建立VPN服务器 pptp 模式的方法
对于想要在外部访问内部的网络,除了在防火墙上开启相应服务器所对应的端口,最好的方法应该是建立VPN-Server,使得用户可以在外网任何一台计算机上拨入到内网中进行操作,而且VPN可以记录详细的日志, ...
- object-C 手动内存管理(MRC)
object-C的内存管理和javascript的垃圾回收不一样,今天总结下手动内存管理,ARC的后边补上. 1:基本铺垫 oc采用引用计数来表示对象的状态,比如通过init创建出来的一个对象引用计数 ...
- 使用sprintf打印float并控制小数位数时引起的问题
最近在做项目中发现一个Bug,直接把进程搞死,查了一下,居然是一个最不起眼的地方导致的,在此记录一下. 先看下面代码 #include <iostream> #include <st ...
- Java学习----finally块
public class Test { String x; public static void main(String[] args) { Test test = new Test(); try { ...
- js快速排序法
var quickSort = function(arr) { if (arr.length <= 1) { return arr; } var pivotIndex = Math.floor( ...
- ie9以上浏览器input文本框/密码框后面的小叉子/小眼睛问题
找了很久不知什么属性控制的这个东西,经过群友的指点重要找到.
- js获取时间天数
date2必须大于date1 function getDays(date1,date2){ /*获取之间的天数*/ /*date1,date2都是date格式*/ var getd=(date2.ge ...
- OpenCV例程实现人脸检测
前段时间看的OpenCV,其实有很多的例子程序,参考代码值得我们学习,对图像特征提取三大法宝:HOG特征,LBP特征,Haar特征有一定了解后. 对本文中的例子程序刚开始没有调通,今晚上调通了,试了试 ...
- C# C/S系统软件开发平台架构图(原创)
企业版V4.0 - 架构图 企业版V4.0 - 桥接功能.后台连接策略 桥接功能是指应用策略模式,由用户配置本地INI文件选择ADO直连(ADO-Direct)或者调用WCF服务接口访问远程服务器后台 ...
- Linux运维需要掌握的技能 (转)
本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了 ...