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 ...
随机推荐
- [解答]对‘’未定义的引用 collect2: 错误: ld 返回 1
写的makefile适用于32位,但是放到64位机器上make就有问题. 需要在makefile中gcc -o....的结尾加上-pthread,例如: bloomfilter.o: bloomfil ...
- OC加强-day01
#pragma mark - 00 知识回顾 1.@property + 类型 + 属性名 :执行的结果 1>在类的.m里面生成一个_属性名的属性 2>生成 _属性名 这个属性的set/g ...
- Repeater 动态增加删除一行
文章参考:文章参考http://www.cnblogs.com/dataadapter/archive/2012/06/25/2562885.html 效果: 前台代码: <%@ Page La ...
- 使用Ubuntu 新建vpn过程
1.更新软件源 sudo apt-get update 2.安装pip sudo apt-get install python-pip 3.安装shadowsocks s ...
- cocos2d-x Android 环境搭建问题汇总
初次接触Cocos2d-x,准备搭建一个hello world的Android环境,问题遇到很多.在此记录,为自己,也为大家,避免重走弯路! 具体的环境搭建,可以参考官方的文档.在Windows7平台 ...
- C++ 虚函数与纯虚函数
#include<iostream> #include<string> using namespace std; class A{ public: virtual void f ...
- Windows phone 之样式的关联
建议大家做界面要用Blend. 做过web的都知道DIV+CSS,给页面元素关联样式有三种方式: 1.内联样式表:就是在每个元素里面写style.优点就是灵活,给指定的元素添加样式.缺点是重用性很差, ...
- DOM 之 document 查找元素方法
DOM 之 document 查找元素方法 getElementById("idName"); // 始终取得第一个 idName 的元素 getElementsByTagName ...
- C#程序中:如何删除xml文件中的节点、元素。
C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...
- JQuery 字符串截取
//字符串截取,全小写 strObj.substring(startIndex,endIndex); //需要注意大小写 strObj.lastIndexOf(String splitObj); // ...