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;
}

原文地址:https://www.cnblogs.com/kuroko-ghh/p/9556627.html

时间: 2024-08-15 02:53:54

ncpc-2014 Catalan Square的相关文章

CSU1576: Catalan Square

Description Input Output Sample Input 0 Sample Output 1 HINT Source NCPC 2014 题目我没看,直接看公式和输出要求就开始做了,意思就是求公式.. 明显大数,java搞起 import java.util.*; import java.math.*; public class Main{ BigInteger[] Cal = new BigInteger[6000]; void GetCal(){ Cal[0]=BigInt

【动态规划】【缩点】NCPC 2014 G Outing

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1793 题目大意: 一辆公交车,上面M个座位,N个人(M<=N<=1000),每个人只有在Ci也上车的情况下才上车.问最多上车几人. 题目思路: [动态规划][缩点] 首先这是一张N个点N条边的有向图.如果J在I也上车的情况下才上车则连一条I到J的边.这样每个点入度最多为1. 这张图有可能有环,所以先缩点,缩完点之后每个环不会有入边,且一定是一个子树的根节点.这样原来的有环的图就变成

【高精度】NCPC 2014 C catalansqure

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789 题目大意: 求大卡特兰数..公式如下.输入n求Sn(n<=5000) 题目思路: [高精度] Sn=Cn+1.直接压四位高精度算一遍就好.只要写高精度乘单精度,高精度除单精度. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorith

【图论】【宽搜】【染色】NCPC 2014 A Ades

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1787 题目大意: N个点M条无向边(N,M<=200000),一个节点只能有一个标记.每条边有一个值{0,1或2}表示这条边连接的两个节点拥有的标记之和.问只要要多少个标记才能满足,无解impossible. 题目思路: [图论][宽搜] 因为每个点只能有或没有标记.所以可以枚举每个联通块的其中一个点有还是没有标记,用这个点去拓展这个点的联通块并01染色(这个点所能到达的所有点) 初

【模拟】NCPC 2014 E ceremony

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1791 题目大意: N栋大楼(N<=100000),拆除的时候有两种选择的操作,可以拆掉一整栋,或者把当前所有大楼的第x层拆掉(高度小于x的没用),并且x以上的所有楼层高度-1.(相当于所有高于x的大楼抽掉一层) 问把N栋大楼拆掉至少要几次拆除操作. 题目思路: [模拟] 先将大楼高度排序,之后考虑分界线,枚举I,I之后的大楼都是被单个拆除,而I和I之前的大楼都是被一层一层拆除.ans

【KMP】【最小表示法】NCPC 2014 H clock pictures

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个针都是相同的,分别指向Ai,Bi(360°被分成360000小份),问能否将其中一个旋转和另一个重合. 题目思路: [KMP][最小表示法] 循环同构问题.可以写KMP,我懒得写KMP了就写了循环同构的最小表示法. 首先将Ai排序,然后求差(记得取模360000,WA了一次),接下来复制一遍开始匹配. A

【模拟】NCPC 2014 D Dice Game

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1790 题目大意: 两个人,每个人有两个骰子,每个骰子可以等概率取[a,b],问哪个人两个骰子期望和更大. 题目思路: [模拟] 签到水题.单个骰子的期望E=0.5*(b+a).所以只需要求和比大小就行. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<a

【模拟】NCPC 2014 K Train passengers

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在车站等待下一班Ci个人.问输入是否合法. 合法:火车上的人不超过M,第一站不能有人下车,最后一站不能有人上车,火车满的时候才能有人在车站等下一班. 题目思路: [图论] 签到水题.模拟到达每个车站的状态即可. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.

CodeForcesGym 100502E Opening Ceremony

Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100502E64-bit integer IO format: %I64d      Java class name: (Any) For the grand opening of the algorithmic games in NlogNsglow, a r