-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQ10303.cpp
99 lines (93 loc) · 1.75 KB
/
Q10303.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <string.h>
struct node {
int s[5010],len;
char sign;
node() {
len = 0;
memset(s,0,sizeof(s));
}
void tran(int num) {
len = 0;
while(num) {
s[len++] = num%10;
num /= 10;
}
}
bool operator <= (node t) const {
if(len < t.len)
return 1;
else if(len > t.len )
return 0;
else {
for(int i=len-1;i>=0;i--) {
if(s[i] < t.s[i])
return 1;
else if(s[i] > t.s[i])
return 0;
}
return 1;
}
}
node operator - (node t) {
node tmp;
int i;
for(i=0;i<len;i++)
tmp.s[i] = s[i]-t.s[i];
for(i=0;i<len;i++)
if(tmp.s[i] < 0) {
tmp.s[i+1]--;
tmp.s[i] += 10;
}
for(i=len-1;i>=0 && tmp.s[i] == 0;i--);
if(i < 0) tmp.len = 1;
else tmp.len = i+1;
return tmp;
}
node operator * (node t) {
int i,j;
node tmp;
for(i=0;i<len;i++)
for(j=0;j<t.len;j++)
tmp.s[i+j] += s[i]*t.s[j];
for(i=0;i<len+t.len+5;i++)
if(tmp.s[i] >= 10) {
tmp.s[i+1] += tmp.s[i]/10;
tmp.s[i] %= 10;
}
for(i=len+t.len+5;i>=0 && tmp.s[i] == 0;i--);
if(i < 0) tmp.len = 1;
else tmp.len = i+1;
return tmp;
}
node operator / (int t) {
node tmp;
int tt = 0,i;
for(i=len-1;i>=0;i--) {
tt = tt*10 + s[i];
tmp.s[i] = tt/t;
tt %= t;
}
for(i=len-1;i>=0 && tmp.s[i] == 0;i--);
if(i < 0) tmp.len = 1;
else tmp.len = i+1;
return tmp;
}
void print() {
for(int i=len-1;i>=0;i--)
printf("%d",s[i]);
puts("");
}
}catalan[1010];
int main() {
int n;
node c,d,tmp;
catalan[1].tran(1);
for(int i=2;i<=1000;i++) {
d.tran(4*i-2);
catalan[i] = catalan[i-1]*d/(i+1);
}
while(scanf("%d",&n) != EOF)
catalan[n].print();
return 0;
}