hdu 1023 Train Problem II

53 篇文章 3 订阅
44 篇文章 0 订阅

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1023

catalan数,公式:h[n] = h[n-1]*(4*n-2)/(n+1);

需要用到高精度,对运算符重载一下。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int MAXN = 110;

struct BigInt
{
    short s[MAXN*2];
    int l;
}c[MAXN];

BigInt operator *(BigInt a, int b)
{
    int i;
    for(i = 0; i < a.l; ++i)
        a.s[i] *= b;
    for(i = 0; i < a.l; ++i)
    {
        a.s[i+1] += a.s[i]/10;
        a.s[i] %= 10;
    }
    while(a.s[a.l] != 0)
    {
        a.s[a.l+1] = a.s[a.l]/10;
        a.s[a.l] %= 10;
        a.l++;
    }
    return a;
}

BigInt operator /(BigInt a, int b)
{
    int i;
    for(i = a.l-1; i > 0; --i)
    {
        a.s[i-1] += a.s[i]%b * 10;
        a.s[i] /= b;
    }
    a.s[0] /= b;
    while(a.s[a.l-1] == 0)
        a.l--;
    return a;
}

void Print(BigInt a)
{
    int i;
    for(i = a.l-1; i >= 0; --i)
        printf("%d", a.s[i]);
    printf("\n");
}

int main()
{
    int i, n;
    c[0].l = 1, c[0].s[0] = 1;
    for(i = 1; i < MAXN; ++i)
        c[i] = c[i-1] * (4*i - 2)/(i+1);
    while(~scanf("%d", &n))
    {
        Print(c[n]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值