刚开始没看出时卡特兰数列。直接套高精度版

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <stack>
  8. #include <queue>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. #include <climits>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <algorithm>
  18. #define LL long long
  19. #define PI 3.1415926535897932626
  20. using namespace std;
  21. int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
  22. const int numlen=;
  23. struct bign {
  24. int len, s[numlen];
  25. bign() {
  26. memset(s, , sizeof(s));
  27. len = ;
  28. }
  29. bign(int num) { *this = num; }
  30. bign(const char *num) { *this = num; }
  31. bign operator = (const int num) {
  32. char s[numlen];
  33. sprintf(s, "%d", num);
  34. *this = s;
  35. return *this;
  36. }
  37. bign operator = (const char *num) {
  38. len = strlen(num);
  39. while(len > && num[] == '') num++, len--;
  40. for(int i = ;i < len; i++) s[i] = num[len-i-] - '';
  41. return *this;
  42. }
  43.  
  44. void deal() {
  45. while(len > && !s[len-]) len--;
  46. }
  47.  
  48. bign operator + (const bign &a) const {
  49. bign ret;
  50. ret.len = ;
  51. int top = max(len, a.len) , add = ;
  52. for(int i = ;add || i < top; i++) {
  53. int now = add;
  54. if(i < len) now += s[i];
  55. if(i < a.len) now += a.s[i];
  56. ret.s[ret.len++] = now%;
  57. add = now/;
  58. }
  59. return ret;
  60. }
  61. bign operator - (const bign &a) const {
  62. bign ret;
  63. ret.len = ;
  64. int cal = ;
  65. for(int i = ;i < len; i++) {
  66. int now = s[i] - cal;
  67. if(i < a.len) now -= a.s[i];
  68. if(now >= ) cal = ;
  69. else {
  70. cal = ; now += ;
  71. }
  72. ret.s[ret.len++] = now;
  73. }
  74. ret.deal();
  75. return ret;
  76. }
  77. bign operator * (const bign &a) const {
  78. bign ret;
  79. ret.len = len + a.len;
  80. for(int i = ;i < len; i++) {
  81. for(int j = ;j < a.len; j++)
  82. ret.s[i+j] += s[i]*a.s[j];
  83. }
  84. for(int i = ;i < ret.len; i++) {
  85. ret.s[i+] += ret.s[i]/;
  86. ret.s[i] %= ;
  87. }
  88. ret.deal();
  89. return ret;
  90. }
  91.  
  92. bign operator * (const int num) {
  93. // printf("num = %d\n", num);
  94. bign ret;
  95. ret.len = ;
  96. int bb = ;
  97. for(int i = ;i < len; i++) {
  98. int now = bb + s[i]*num;
  99. ret.s[ret.len++] = now%;
  100. bb = now/;
  101. }
  102. while(bb) {
  103. ret.s[ret.len++] = bb % ;
  104. bb /= ;
  105. }
  106. ret.deal();
  107. return ret;
  108. }
  109.  
  110. bign operator / (const bign &a) const {
  111. bign ret, cur = ;
  112. ret.len = len;
  113. for(int i = len-;i >= ; i--) {
  114. cur = cur*;
  115. cur.s[] = s[i];
  116. while(cur >= a) {
  117. cur -= a;
  118. ret.s[i]++;
  119. }
  120. }
  121. ret.deal();
  122. return ret;
  123. }
  124.  
  125. bign operator % (const bign &a) const {
  126. bign b = *this / a;
  127. return *this - b*a;
  128. }
  129.  
  130. bign operator += (const bign &a) { *this = *this + a; return *this; }
  131. bign operator -= (const bign &a) { *this = *this - a; return *this; }
  132. bign operator *= (const bign &a) { *this = *this * a; return *this; }
  133. bign operator /= (const bign &a) { *this = *this / a; return *this; }
  134. bign operator %= (const bign &a) { *this = *this % a; return *this; }
  135.  
  136. bool operator < (const bign &a) const {
  137. if(len != a.len) return len < a.len;
  138. for(int i = len-;i >= ; i--) if(s[i] != a.s[i])
  139. return s[i] < a.s[i];
  140. return false;
  141. }
  142. bool operator > (const bign &a) const { return a < *this; }
  143. bool operator <= (const bign &a) const { return !(*this > a); }
  144. bool operator >= (const bign &a) const { return !(*this < a); }
  145. bool operator == (const bign &a) const { return !(*this > a || *this < a); }
  146. bool operator != (const bign &a) const { return *this > a || *this < a; }
  147.  
  148. string str() const {
  149. string ret = "";
  150. for(int i = ;i < len; i++) ret = char(s[i] + '') + ret;
  151. return ret;
  152. }
  153. };
  154. istream& operator >> (istream &in, bign &x) {
  155. string s;
  156. in >> s;
  157. x = s.c_str();
  158. return in;
  159. }
  160. ostream& operator << (ostream &out, const bign &x) {
  161. out << x.str();
  162. return out;
  163. }
  164. #define MAXN 1005
  165. bign ans[MAXN];
  166. int N;
  167. void init()
  168. {
  169. ans[]=;
  170. ans[]=;
  171. for (int i=;i<MAXN;i++)
  172. {
  173. ans[i]=ans[i-]*(*i-);
  174. ans[i]/=(i+);
  175. }
  176. }
  177. int main()
  178. {
  179. init();
  180. while (cin>>N)
  181. cout<<ans[N]<<endl;
  182. return ;
  183. }

UVA 10303 How Many Trees? (catlan)的更多相关文章

  1. UVA 10303 - How Many Trees?(数论 卡特兰数 高精度)

    Problem D How Many Trees? Input: standard input Output: standard output Memory Limit: 32 MB A binary ...

  2. UVa 10562 Undraw the Trees 看图写树

    转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...

  3. UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)

    题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...

  4. uva 10007 Count the Trees

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  5. UVa 10562 Undraw the Trees(递归遍历)

    题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...

  6. uva 10562 undraw the trees(烂题) ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...

  7. uva 10303

    卡特兰数  但是个高精度 一开始用最普通的递推式 超时了 百度百科了一下 用另类递推式过了 ~~ 这个大数类是做数据结构课程设计的时候写的... #include <cstdio> #in ...

  8. UVa 10088 (Pick定理) Trees on My Island

    这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...

  9. UVa 10562 Undraw the Trees

    题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...

随机推荐

  1. hdu5863 cjj's string game

    矩阵快速幂 #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = ...

  2. Django,Celery, rabbitmq

    学习Django 2 by Example书中的456页,运行 celery -A myshop worker -l info 报错.虽然特别指定了Celery的版本,也没用.之前使用的是标准安装:下 ...

  3. React错误总结(三)

    神坑react native之Cannot Add a child that doesn't have a YogaNode to a parent with out a measure functi ...

  4. 【集训试题】SiriusRen的卡牌 set

    题意概述: 给出N张卡牌,每张有三个属性a,b,c,同时给出所有属性可能的最大值A,B,C.对于一张卡牌,当这张卡牌至少有两个属性大于另外一张卡牌的对应两个属性的时候,认为这张卡牌更加优秀.现在问有多 ...

  5. lintcode-74-第一个错误的代码版本

    74-第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...

  6. Linux挂载Win共享文件夹_VmwareTools

  7. jsp中的session和上下文

    Session的典型应用: 防止用户非法登录到某个页面. 网上商城的购物车 保存用户登录信息 注:多个请求要用的东西放在session中,多个会话之间要用的东西放在上下文中. 如何创建session? ...

  8. BZOJ4290 传送门

    昨天考试考了这道题,学校评测不开O2被卡的一愣一愣的. 这种题线性复杂度就线性复杂度,为什么要卡常数. 顺便提一句,GRH大爷O(m*n*ans)的算法有90分,我的O(m*n)算法75.(万恶的ST ...

  9. BZOJ5343 [Ctsc2018]混合果汁 【二分 + 主席树】

    题目链接 BZOJ5343 题解 明显要二分一下美味度,然后用尽量少的价格去购买饮料,看看能否买到\(L\)升,然后看看能否控制价格在\(g\)内 尽量少的价格,就优先先选完便宜的饮料,由于询问的是一 ...

  10. POJ3294 Life Forms 【后缀数组】

    生命形式 时间限制: 5000MS   内存限制: 65536K 提交总数: 16660   接受: 4910 描述 你可能想知道为什么大多数外星人的生命形式与人类相似,不同的是表面特征,如身高,肤色 ...