zoukankan      html  css  js  c++  java
  • ncpc-2014 Catalan Square

    Catalan Square

    注意的是等于Cn+1

    高精度卡特兰数

    #include<bits/stdc++.h>
    #define BASE 10000
    #define MAX 100010
    using namespace std;
    
    struct BigInt{
        int num[MAX],len;
    
        BigInt(int _ = 0) {
            num[len = 1] = _;
        }
        BigInt operator +(const BigInt &a)const {
            BigInt re;
            re.len = max(len,a.len);
            int temp = 0;
            for(int i = 1; i <= a.len; ++i) {
                re.num[i] = temp + num[i] + a.num[i];
                temp = re.num[i] / BASE;
                re.num[i] %= BASE;
            }
            if(temp)    re.num[++re.len] = temp;
            return re;
        }
        BigInt operator *(int a)const {
            BigInt re;
            re.len = len;
            int temp = 0;
            for(int i = 1; i <= len; ++i) {
                re.num[i] = temp + num[i] * a;
                temp = re.num[i] / BASE;
                re.num[i] %= BASE;
            }
            while(temp) re.num[++re.len] = temp % BASE,temp /= BASE;
            return re;
        }
        BigInt operator /(int a)const {
            BigInt re;
            re.len = len;
            int temp = 0;
            for(int i = len; i; --i) {
                re.num[i] = (temp + num[i]) / a;
                temp = (temp + num[i]) % a * BASE;
            }
            while(!re.num[re.len])  --re.len;
            return re;
        }
    };
    
    int main()
    {   
        //freopen("in.txt","r",stdin);
        int x;
        cin >> x;
        x=x+1;
        BigInt ans(1);
        for(int i = 2; i <= x; ++i)
            ans = ans * (4 * i - 2) / (i + 1);
        printf("%d",ans.num[ans.len]);
        for(int i = ans.len - 1; i; --i)
            printf("%04d",ans.num[i]);
        return 0;
    }
    View Code
  • 相关阅读:
    Git 常用命令大全-转载
    Powershell重命名文件夹
    C#使用qq邮箱发送邮件
    iOS开发-YUV颜色格式
    iOS开发小记(十一)
    iOS开发-AFNetworking
    iOS开发-NSURLSession
    iOS开发-类的加载load函数和initialize函数
    iOS开发-调试(debug)
    iOS开发-graphics
  • 原文地址:https://www.cnblogs.com/kuroko-ghh/p/9556627.html
Copyright © 2011-2022 走看看