题目链接: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了,所以要用高精度。而且要约分。

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. int GCD(int a,int b)
  8. {
  9. if(a < b) swap(a,b);
  10. if(a % b == ) return b;
  11. return GCD(b,a%b);
  12. }
  13.  
  14. int ans[],cnt;
  15.  
  16. void BigIntergerMul(int n)
  17. {
  18. int b[],pv=;
  19.  
  20. int temp = n;
  21. while(temp)
  22. {
  23. b[++pv] = temp%;
  24. temp /= ;
  25. }
  26.  
  27. if(cnt == )
  28. {
  29. for(int i=; i<=pv; i++)
  30. {
  31. ans[i] = b[i];
  32. }
  33. cnt = pv;
  34. }
  35. else
  36. {
  37. int c[],cnt1 = ;
  38. memset(c,,sizeof(c));
  39.  
  40. for(int i=; i<=pv; i++)
  41. {
  42. for(int j=; j<=cnt; j++)
  43. {
  44. int mul = b[i]*ans[j];
  45. int wei = j + i - ;
  46.  
  47. c[wei] += mul;
  48.  
  49. while(c[wei] >= ){
  50. c[wei+] += c[wei]/;
  51. c[wei] = c[wei]%;
  52. wei++;
  53. }
  54. cnt1 = max(wei,cnt1);
  55. }
  56. }
  57. cnt = max(cnt,cnt1);
  58. for(int i=; i<=cnt; i++)
  59. {
  60. ans[i] = c[i];
  61. }
  62. }
  63.  
  64. }
  65.  
  66. int main()
  67. {
  68. //freopen("E:\\acm\\input.txt","r",stdin);
  69. int T;
  70. cin>>T;
  71. while(T--)
  72. {
  73. int M,N;
  74. cin>>M>>N;
  75. cnt = ;
  76. memset(ansff,,sizeof(ans));
  77. int fenzi = N;
  78. for(int i=; i<N; i++)
  79. {
  80. int gcd = GCD(M,fenzi); //先分子与M约分,在用高精度相乘,这样不用最后两个高精度来约分。
  81. fenzi = fenzi/gcd;
  82. BigIntergerMul(M/gcd);
  83. }
  84. printf("%d/",fenzi);
  85. for(int i=cnt; i>=; i--)
  86. {
  87. printf("%d",ans[i]);
  88. }
  89. printf("\n");
  90. }
  91. }

hdu 4762 Cut the Cake概率公式的更多相关文章

  1. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. 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 ...

  3. HDU 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...

  4. 2013长春网赛1004 hdu 4762 Cut the Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...

  5. HDU 4762 Cut the Cake(高精度)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. hdu 4762 Cut the Cake (大数乘法)

    猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...

  7. HDU 4328 Cut the cake

    Cut the cake Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. hdoj 4762 Cut the Cake

    题意很简单就不说了. 解题的关键就是这个公式 answer=n/(m^(n-1)); 要用到大数的乘法.然后java水过. import java.util.*; import java.math.* ...

  9. HDU 2134 Cuts the cake

    http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...

随机推荐

  1. Apache Shiro 快速入门教程,shiro 基础教程 (这篇文章非常好)

    第一部分 什么是Apache Shiro     1.什么是 apache shiro :   Apache Shiro是一个功能强大且易于使用的Java安全框架,提供了认证,授权,加密,和会话管理 ...

  2. [uiview animation ...] 这个函数有多少没有认识的可能!翻盘效果 上下左右怎么翻都不怕

    1.自己还想着怎么3d 变形    让一个视图绕x/y 轴线翻转 就这么一句代码 [UIView transitionWithView:self.startButton duration:0.5 op ...

  3. 第4条:多用类型常量,少用#define预处理指令

    定义常量的几种方式: 1.#define ANIMATION_DURAION 0.3         //定义了一个动画时长的常量, 预处理过程会把碰到的所有ANIMATION_DURAION一律替换 ...

  4. C++专题 - 面向对象总结

    1.         什么是类?什么是对象?对象与类的关系是什么? 答:类就是相同的数据和相同的一组对象的集合,即类是对具有相同数据结构和相同操作的一类对象的描述: 对象是描述其属性的数据以及对这些数 ...

  5. Java-jfree报表(学习整理)----饼状图、柱状图、折线统计图

    1.使用的报表工具: jfree报表 2.下载网址: http://www.jfree.org/ 下载之后先解压:如下图 下载后:需要的jar包!如下图: 打开:找到以下的两个jar包 再导入开发项目 ...

  6. SGU Volume 2

    SGU200.Cracking RSA------------------------★高斯消元 SGU207.Robbers -------------------------------数论 SG ...

  7. ARM开发板系统移植-----rootfs的制作

    前面两篇文章分别介绍了mini2440开发板上运行的bootloader和kernel,到这里系统启动后其实是停留在一个“僵死”的状态---无法挂载根文件系统. 这里将介绍如何制作一个根文件系统,并且 ...

  8. codeblocks调试(转载)

    单步调试  1)设置断点  在需要设置断点处,右击左边行号,Add breakpoint,则出现一个红色的点(可以同时设置多个,前提是不能在debug的运行模式下). 2)调试运行 Debug-> ...

  9. Jquery Mobile下设置radio控件选中

    问题: .html文件头部引入了: <script src="js/jquery.js"></script> <script src="js ...

  10. php ob_ 开头的相关函数

    <?phpbool ob_start([ callback $output_callback [, int $chunk_size [, bool $erase ]]]); /* 打开输出控制缓 ...