Problem Description
This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.

It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?

 
Input
Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.

 
Output
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.

 
Sample Input
2
3
-1
 
Sample Output
2
5
 
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int n;
#define BASE 10000
#define UNIT 4
#define FORMAT "%04d" class BigNum{
public:
int a[20];
int length;
BigNum(const int k){ //用小于BASE的k初始化大数
memset(a, 0, sizeof(a));
a[0] = k;
length = 1;
}
BigNum(){
memset(a, 0, sizeof(a));
length = 0;
}
BigNum operator * (const BigNum & B){
BigNum ans;
int i,j,up=0,num;
for(i=0; i<length; i++){
up = 0; //每次循环都要初始化为0
for(j=0; j<B.length; j++){
num = up + a[i] * B.a[j] + ans.a[i+j];
up = num / BASE;
num = num % BASE;
// cout << num << endl;
ans.a[i+j] = num;
}
// cout << up << endl;
if(up > 0)
ans.a[i+j] = up;
}
ans.length = i+j;
while(ans.a[ans.length -1] == 0 && ans.length > 1)
ans.length--;
return ans;
}
BigNum operator /(const int & k) const{ // k < BASE, 对此题适用
BigNum ans;
int down=0,i,num;
for(i=length-1; i>=0; i--){
num = ( (down * BASE) + a[i] ) / k;
down = ( (down * BASE) + a[i] ) % k;
ans.a[i] = num;
}
ans.length = length;
while(ans.a[ans.length-1] == 0 && ans.length > 1)
ans.length -- ;
return ans;
}
void print(){
printf("%d", a[length-1]);
for(int i=length-2; i>=0; i--)
printf(FORMAT,a[i]);
}
}; //f(n) = C(2n,n)/(n+1)
int main(){
BigNum nums[101];
nums[1] = BigNum(1);
nums[2] = BigNum(2);
nums[3] = BigNum(5);
for(int i=4; i<=100; i++){
nums[i] = nums[i-1] * (4*i-2)/(i+1);
}
int n;
while(scanf("%d", &n), n>0){
nums[n].print();
printf("\n");
}
return 0;
}

HDU 1134 卡特兰数 大数乘法除法的更多相关文章

  1. 2014年百度之星程序设计大赛 - 初赛(第一轮) hdu Grids (卡特兰数 大数除法取余 扩展gcd)

    题目链接 分析:打表以后就能发现时卡特兰数, 但是有除法取余. f[i] = f[i-1]*(4*i - 2)/(i+1); 看了一下网上的题解,照着题解写了下面的代码,不过还是不明白,为什么用扩展g ...

  2. hdu-1130(卡特兰数+大数乘法,除法模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...

  3. hdu 1130,hdu 1131(卡特兰数,大数)

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. HDU 1134 Game of Connections(卡特兰数+大数模板)

    题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...

  5. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  7. hdu 1023 卡特兰数《 大数》java

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  9. 【hdoj_1133】Buy the Ticket(卡特兰数+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元 ...

随机推荐

  1. NEC红外遥控协议理解与实现

    红外发射管有2个管脚,发送的是经过38KHz时钟调制过的信号.例如下图使用PWM产生一个等占空时钟信号用于调制. 接收管收下来的信号已经经过了解调,可以直接连接系统的外部中断脚. 下面通过逻辑分析仪来 ...

  2. Erlang语言介绍

    Erlang (/ˈɜrlæŋ/ er-lang) is a general-purpose concurrent, garbage-collected programming language an ...

  3. 2014第6周五JS调试

    今天才发现chrome调试前端尤其是JS真是很方便,难怪之前公司几个前端高手都用chrome的开发者工具来调试.把今天知道的chrome调试方法收集整理一下,在今后的开发调试中都可能会用到: Prof ...

  4. [Leetcode][Python]48: Rotate Image

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 48: Rotate Imagehttps://leetcode.com/pr ...

  5. relay 2015-02-05 21:00 27人阅读 评论(0) 收藏

    scanf函数是以在输入多个数值数据时,若格式控制串中没有非格式字符作输入数据之间的间隔,则可用空格,TAB或回车作间隔. C编译在碰到空格,TAB,回车或非法数据(如对"%d"输 ...

  6. 【LeetCode练习题】Gas Station

    Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...

  7. myeclipse 2013 git

    1. 2.添加site http://download.eclipse.org/egit/updates-2.3 3.安装 完成后,查看windows->preference的team下面有gi ...

  8. 常用的CSS清除浮动的方法优缺点分析(个人学习笔记)

    一.抛一块问题砖(display: block)先看现象: 分析HTML代码结构: <div class="outer"> <div class="di ...

  9. appium自动化测试

    appium官网:http://appium.io/index.html?lang=zh Requirements Your environment needs to be setup for the ...

  10. Apache 日志配置,包含过滤配置

    最近排查支付宝交易成功后异步通知执行失败的原因,需要查看Apache的日志,发现之前一直没对日志进行设置,结果日志文件都1.5G多了,于是搜索了如何按天记录日志. 但公司的网站是通过阿里云的SLB分发 ...