如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。

URAL/1625

来自"NOCOW"

跳转到: 导航, 搜索

输出1至n*2-1项catalan数即可。

#include <iostream>
using namespace std;
const int mod=10000;
struct LL
{
    int t[101],cnt;
    LL()
    {
        memset(t,0,sizeof(t));
        cnt=1;
    }
}h[201];
int n;
inline LL operator * (const LL& a,int x)
{
    LL b=a;
    for (int i=1;i<=b.cnt;++i)
        b.t[i]*=x;
    for (int i=1;i<=b.cnt;++i)
    {
        b.t[i+1]+=b.t[i]/mod;
        b.t[i]%=mod;
    }
    if (b.t[b.cnt+1])  ++b.cnt;
    return b;
}
inline void operator /= (LL &a,int x)
{
    for (int i=a.cnt;i;--i)
    {
        a.t[i-1]+=a.t[i]%x*mod;
        a.t[i]/=x;
    }
    if ((!a.t[a.cnt]) && (a.cnt > 1))
        --a.cnt;
}
inline void print(int x)
{
    cout << h[x].t[h[x].cnt--];
    while (h[x].cnt)
    {
        cout.width(4);
        cout.fill('0');
        cout << h[x].t[h[x].cnt--];
    }
    cout << endl;
}
int main()
{
    cin >> n;
    h[1].t[1]=1;
    for (int i=2;i<(n<<1);++i)
    {
        h[i]=h[i-1]*((i<<2)-2);
        h[i]/=(i+1);
    }
    for (int i=1;i<(n<<1);++i)
        print(i);
    return 0;
}
//by zzy
个人工具