UVA 10303 How Many Trees? (catlan)
刚开始没看出时卡特兰数列。直接套高精度版
- #include <map>
- #include <set>
- #include <list>
- #include <cmath>
- #include <ctime>
- #include <deque>
- #include <stack>
- #include <queue>
- #include <cctype>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <climits>
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- #define LL long long
- #define PI 3.1415926535897932626
- using namespace std;
- int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
- const int numlen=;
- struct bign {
- int len, s[numlen];
- bign() {
- memset(s, , sizeof(s));
- len = ;
- }
- bign(int num) { *this = num; }
- bign(const char *num) { *this = num; }
- bign operator = (const int num) {
- char s[numlen];
- sprintf(s, "%d", num);
- *this = s;
- return *this;
- }
- bign operator = (const char *num) {
- len = strlen(num);
- while(len > && num[] == '') num++, len--;
- for(int i = ;i < len; i++) s[i] = num[len-i-] - '';
- return *this;
- }
- void deal() {
- while(len > && !s[len-]) len--;
- }
- bign operator + (const bign &a) const {
- bign ret;
- ret.len = ;
- int top = max(len, a.len) , add = ;
- for(int i = ;add || i < top; i++) {
- int now = add;
- if(i < len) now += s[i];
- if(i < a.len) now += a.s[i];
- ret.s[ret.len++] = now%;
- add = now/;
- }
- return ret;
- }
- bign operator - (const bign &a) const {
- bign ret;
- ret.len = ;
- int cal = ;
- for(int i = ;i < len; i++) {
- int now = s[i] - cal;
- if(i < a.len) now -= a.s[i];
- if(now >= ) cal = ;
- else {
- cal = ; now += ;
- }
- ret.s[ret.len++] = now;
- }
- ret.deal();
- return ret;
- }
- bign operator * (const bign &a) const {
- bign ret;
- ret.len = len + a.len;
- for(int i = ;i < len; i++) {
- for(int j = ;j < a.len; j++)
- ret.s[i+j] += s[i]*a.s[j];
- }
- for(int i = ;i < ret.len; i++) {
- ret.s[i+] += ret.s[i]/;
- ret.s[i] %= ;
- }
- ret.deal();
- return ret;
- }
- bign operator * (const int num) {
- // printf("num = %d\n", num);
- bign ret;
- ret.len = ;
- int bb = ;
- for(int i = ;i < len; i++) {
- int now = bb + s[i]*num;
- ret.s[ret.len++] = now%;
- bb = now/;
- }
- while(bb) {
- ret.s[ret.len++] = bb % ;
- bb /= ;
- }
- ret.deal();
- return ret;
- }
- bign operator / (const bign &a) const {
- bign ret, cur = ;
- ret.len = len;
- for(int i = len-;i >= ; i--) {
- cur = cur*;
- cur.s[] = s[i];
- while(cur >= a) {
- cur -= a;
- ret.s[i]++;
- }
- }
- ret.deal();
- return ret;
- }
- bign operator % (const bign &a) const {
- bign b = *this / a;
- return *this - b*a;
- }
- bign operator += (const bign &a) { *this = *this + a; return *this; }
- bign operator -= (const bign &a) { *this = *this - a; return *this; }
- bign operator *= (const bign &a) { *this = *this * a; return *this; }
- bign operator /= (const bign &a) { *this = *this / a; return *this; }
- bign operator %= (const bign &a) { *this = *this % a; return *this; }
- bool operator < (const bign &a) const {
- if(len != a.len) return len < a.len;
- for(int i = len-;i >= ; i--) if(s[i] != a.s[i])
- return s[i] < a.s[i];
- return false;
- }
- bool operator > (const bign &a) const { return a < *this; }
- bool operator <= (const bign &a) const { return !(*this > a); }
- bool operator >= (const bign &a) const { return !(*this < a); }
- bool operator == (const bign &a) const { return !(*this > a || *this < a); }
- bool operator != (const bign &a) const { return *this > a || *this < a; }
- string str() const {
- string ret = "";
- for(int i = ;i < len; i++) ret = char(s[i] + '') + ret;
- return ret;
- }
- };
- istream& operator >> (istream &in, bign &x) {
- string s;
- in >> s;
- x = s.c_str();
- return in;
- }
- ostream& operator << (ostream &out, const bign &x) {
- out << x.str();
- return out;
- }
- #define MAXN 1005
- bign ans[MAXN];
- int N;
- void init()
- {
- ans[]=;
- ans[]=;
- for (int i=;i<MAXN;i++)
- {
- ans[i]=ans[i-]*(*i-);
- ans[i]/=(i+);
- }
- }
- int main()
- {
- init();
- while (cin>>N)
- cout<<ans[N]<<endl;
- return ;
- }
UVA 10303 How Many Trees? (catlan)的更多相关文章
- UVA 10303 - How Many Trees?(数论 卡特兰数 高精度)
Problem D How Many Trees? Input: standard input Output: standard output Memory Limit: 32 MB A binary ...
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
- UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)
题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...
- uva 10007 Count the Trees
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10562 Undraw the Trees(递归遍历)
题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...
- uva 10562 undraw the trees(烂题) ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...
- uva 10303
卡特兰数 但是个高精度 一开始用最普通的递推式 超时了 百度百科了一下 用另类递推式过了 ~~ 这个大数类是做数据结构课程设计的时候写的... #include <cstdio> #in ...
- UVa 10088 (Pick定理) Trees on My Island
这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...
- UVa 10562 Undraw the Trees
题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...
随机推荐
- hdu5863 cjj's string game
矩阵快速幂 #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = ...
- Django,Celery, rabbitmq
学习Django 2 by Example书中的456页,运行 celery -A myshop worker -l info 报错.虽然特别指定了Celery的版本,也没用.之前使用的是标准安装:下 ...
- React错误总结(三)
神坑react native之Cannot Add a child that doesn't have a YogaNode to a parent with out a measure functi ...
- 【集训试题】SiriusRen的卡牌 set
题意概述: 给出N张卡牌,每张有三个属性a,b,c,同时给出所有属性可能的最大值A,B,C.对于一张卡牌,当这张卡牌至少有两个属性大于另外一张卡牌的对应两个属性的时候,认为这张卡牌更加优秀.现在问有多 ...
- lintcode-74-第一个错误的代码版本
74-第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...
- Linux挂载Win共享文件夹_VmwareTools
- jsp中的session和上下文
Session的典型应用: 防止用户非法登录到某个页面. 网上商城的购物车 保存用户登录信息 注:多个请求要用的东西放在session中,多个会话之间要用的东西放在上下文中. 如何创建session? ...
- BZOJ4290 传送门
昨天考试考了这道题,学校评测不开O2被卡的一愣一愣的. 这种题线性复杂度就线性复杂度,为什么要卡常数. 顺便提一句,GRH大爷O(m*n*ans)的算法有90分,我的O(m*n)算法75.(万恶的ST ...
- BZOJ5343 [Ctsc2018]混合果汁 【二分 + 主席树】
题目链接 BZOJ5343 题解 明显要二分一下美味度,然后用尽量少的价格去购买饮料,看看能否买到\(L\)升,然后看看能否控制价格在\(g\)内 尽量少的价格,就优先先选完便宜的饮料,由于询问的是一 ...
- POJ3294 Life Forms 【后缀数组】
生命形式 时间限制: 5000MS 内存限制: 65536K 提交总数: 16660 接受: 4910 描述 你可能想知道为什么大多数外星人的生命形式与人类相似,不同的是表面特征,如身高,肤色 ...