**链接:****传送门 **

题意:裸卡特兰数,但是必须用大数做

balabala:上交高精度模板题,增加一下熟悉度


  1. /*************************************************************************
  2. > File Name: hdu1023.cpp
  3. > Author: WArobot
  4. > Blog: http://www.cnblogs.com/WArobot/
  5. > Created Time: 2017年05月11日 星期四 19时25分09秒
  6. ************************************************************************/
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. const int maxlen = 10000;
  10. class HP{ public:
  11. int len , s[maxlen];
  12. HP(){ (*this) = 0; };
  13. HP(int inte){ (*this) = inte; }; HP(const char *str){ (*this)=str; };
  14. friend ostream & operator<<(ostream &cout,const HP &x);
  15. HP operator = (int inte); HP operator = (const char*str);
  16. HP operator * (const HP &b); HP operator - (const HP &b);
  17. HP operator / (const HP &b); int Compare (const HP &b);
  18. HP operator + (const HP &b);
  19. };
  20. ostream& operator <<(ostream & cout,const HP &x){
  21. for(int i=x.len ; i>=1 ; i--) cout<<x.s[i]; return cout;
  22. }
  23. HP HP::operator = (const char *str){
  24. len = strlen(str);
  25. for(int i=1;i<=len;i++) s[i] = str[len-i]-'0';
  26. return *this;
  27. }
  28. HP HP::operator = (int inte){
  29. if(inte==0){ len = 1; s[1] = 0; return(*this); };
  30. for(len = 0;inte>0;){ s[++len]=inte%10; inte/=10; };
  31. return (*this);
  32. }
  33. HP HP::operator * (const HP &b){
  34. int i,j;
  35. HP c;
  36. c.len = len + b.len;
  37. for(i=1;i<=c.len;i++) c.s[i] = 0;
  38. for(i=1;i<=len;i++) for(j=1;j<=b.len;j++) c.s[i+j-1] += s[i]*b.s[j];
  39. for(i=1;i<c.len;i++){ c.s[i+1] += c.s[i]/10; c.s[i] %= 10; };
  40. while(c.s[i]) { c.s[i+1] = c.s[i]/10 ; c.s[i] %= 10 ; i++; }
  41. while(i>1 && !c.s[i]) i--; c.len = i;
  42. return c;
  43. }
  44. HP HP::operator - (const HP &b){
  45. int i,j; HP c;
  46. for(i=1,j=0;i<=len;i++){
  47. c.s[i] = s[i] - j; if(i<=b.len) c.s[i] -= b.s[i];
  48. if(c.s[i]<0){ j=1; c.s[i]+=10; } else j = 0;
  49. }
  50. c.len = len; while(c.len>1 && !c.s[c.len]) c.len--;
  51. return c;
  52. }
  53. int HP::Compare(const HP &y){
  54. if(len>y.len) return 1;
  55. if(len<y.len) return -1;
  56. int i = len;
  57. while( (i>1)&&( s[i]==y.s[i] ) ) i--;
  58. return s[i]-y.s[i];
  59. }
  60. HP HP::operator / (const HP &b){
  61. int i,j; HP d(0),c;
  62. for(i=len;i>0;i--){
  63. if( !(d.len==1 && d.s[1]==0) )
  64. { for( j = d.len; j>0;j--) d.s[j+1] = d.s[j]; ++d.len; }
  65. d.s[1] = s[i]; c.s[i] = 0;
  66. while( (j=d.Compare(b))>=0 )
  67. { d = d-b; c.s[i]++; if(j==0) break; }
  68. }
  69. c.len = len; while( (c.len>1)&&(c.s[c.len]==0) ) c.len--;
  70. return c;
  71. }
  72. HP HP::operator + (const HP &b){
  73. int i; HP c; c.s[1] = 0;
  74. for(i = 1; i<=len || i<=b.len || c.s[i]; i++ ){
  75. if( i<=len ) c.s[i] += s[i];
  76. if( i<=b.len ) c.s[i] += b.s[i];
  77. c.s[i+1] = c.s[i]/10; c.s[i] %= 10;
  78. }
  79. c.len = i-1; if( c.len == 0 ) c.len = 1;
  80. return c;
  81. }
  82. int main(){
  83. HP h[102];
  84. h[0] = h[1] = 1;
  85. for(int i=2;i<=100;i++){
  86. for(int j=0;j<i;j++){
  87. h[i] = h[i] + (h[j]*h[i-1-j]);
  88. }
  89. }
  90. int n;
  91. while(~scanf("%d",&n)){
  92. cout<<h[n]<<endl;
  93. }
  94. return 0;
  95. }

HDU 1023 Train Problem II( 大数卡特兰 )的更多相关文章

  1. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

  2. HDU 1023 Train Problem II (大数卡特兰数)

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  4. 1023 Train Problem II(卡特兰数)

    Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...

  5. HDU 1023 Train Problem II (卡特兰数,经典)

    题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...

  6. Train Problem II(卡特兰数 组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...

  7. Train Problem II(卡特兰数+大数乘除)

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Train Problem II (卡特兰数+大数问题)

    卡特兰数: Catalan数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) ...

  9. HDOJ 1023 Train Problem II 卡特兰数

    火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...

随机推荐

  1. UVA 12633 Super Rooks on Chessboard (生成函数+FFT)

    题面传送门 题目大意:给你一张网格,上面有很多骑士,每个骑士能横着竖着斜着攻击一条直线上的格子,求没被攻击的格子的数量总和 好神奇的卷积 假设骑士不能斜着攻击 那么答案就是没被攻击的 行数*列数 接下 ...

  2. groupadd(创建组)重要参数介绍

    -g :值定用户组GID值.除非接 -o 参数(如:groupadd -g 666 -o oldboy),否则ID值必须是唯一的数字(不能为负数). 如果不指定 -g 参数,则默认从500开始 

  3. 使用动态代理实现dao接口

    使用动态代理实现dao接口的实现类 MyBatis允许只声明一个dao接口,而无需写dao实现类的方式实现数据库操作.前提是必须保证Mapper文件中的<mapper>标签的namespa ...

  4. Linux常用命令last的使用方法详解

    http://www.jb51.net/article/120140.htm 最近在学习linux命令,学习到了last命令,发现很多同学对last命令不是很熟悉,last命令的功能列出目前与过去登入 ...

  5. 解决was6版本号过期问题

    原创作品.出自 "深蓝的blog" 博客,欢迎转载.转载时请务必注明出处.否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlong ...

  6. 王立平--split字符串切割

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  7. poj 3356

    Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...

  8. 关于server和虚拟主机的差别

    文章都是先由本人个人博客,孙占兴:www.teilim.com,先更新,随后CSDN博客才会更新.掌握第一动态请关注本人主站. 原文链接:http://www.teilim.com/guan-yu-y ...

  9. 局域网网络性能測试方法HDtune 64K有缓存測速法,让你得知你的网络性能

    该方法能够有效測试出您的网络传输性能究竟有多高,该方法通用于有盘,无盘(系统虚拟盘) ,游戏虚拟盘,以及其它带有缓存功能的虚拟盘软件,可是由于每款软件的工作方式和原理都不仅同样,所以每款软件的測试结果 ...

  10. tomcat开启https服务

    一.创建证书 证书是单点登录认证系统中很重要的一把钥匙,客户端于服务器的交互安全靠的就是证书:本教程由于是演示所以就自己用JDK自带的keytool工具生成证书:如果以后真正在产品环境中使用肯定要去证 ...