POJ2084卡特兰数如何使用高精度算法实现?
- 内容介绍
- 文章标签
- 相关推荐
本文共计979个文字,预计阅读时间需要4分钟。
“Game of Connections时间限制:1000MS,内存限制:30000K,总提交次数:7次,已接受:3625次
游戏描述:这是一个小型但古老的游
GameofConnectionsTimeLimit:1000MS MemoryLimit:30000KTotalSubmissions:7 Game of ConnectionsTime Limit: 1000MSMemory Limit: 30000KTotal Submissions: 7136Accepted: 3625Description
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
23-1
Sample Output
25
Source
我是巩固一下卡特兰数,顺便存一下高精度模板的。
代码:
/* ***********************************************Author :rabbitCreated Time :2014/3/27 13:57:20File Name :7.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x3f3f3f3f#define eps 1e-8#define pi acos(-1.0)typedef long long ll;const int maxn=9999;const int maxsize=2020;const int dlen=4;class BigNum{private:int a[1000],len;public:BigNum(){len=1;memset(a,0,sizeof(a));}BigNum(const int b){int c,d=b;len=0;memset(a,0,sizeof(a));while(d>maxn){c=d-(d/(maxn+1))*(maxn+1);d=d/(maxn+1);a[len++]=c;}a[len++]=d;}BigNum(const char *s){int t,k,index,L,i;memset(a,0,sizeof(a));L=strlen(s);len=L/dlen;if(L%dlen)len++;index=0;for(int i=L-1;i>=0;i-=dlen){t=0;k=i-dlen+1;if(k<0)k=0;for(int j=k;j<=i;j++)t=t*10+s[j]-‘0‘;a[index++]=t;}}BigNum(const BigNum memset(a,0,sizeof(a));for(int i=0;i
POJ 2084 卡特兰数+高精度模板,布布扣,bubuko.com
本文共计979个文字,预计阅读时间需要4分钟。
“Game of Connections时间限制:1000MS,内存限制:30000K,总提交次数:7次,已接受:3625次
游戏描述:这是一个小型但古老的游
GameofConnectionsTimeLimit:1000MS MemoryLimit:30000KTotalSubmissions:7 Game of ConnectionsTime Limit: 1000MSMemory Limit: 30000KTotal Submissions: 7136Accepted: 3625Description
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
23-1
Sample Output
25
Source
我是巩固一下卡特兰数,顺便存一下高精度模板的。
代码:
/* ***********************************************Author :rabbitCreated Time :2014/3/27 13:57:20File Name :7.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x3f3f3f3f#define eps 1e-8#define pi acos(-1.0)typedef long long ll;const int maxn=9999;const int maxsize=2020;const int dlen=4;class BigNum{private:int a[1000],len;public:BigNum(){len=1;memset(a,0,sizeof(a));}BigNum(const int b){int c,d=b;len=0;memset(a,0,sizeof(a));while(d>maxn){c=d-(d/(maxn+1))*(maxn+1);d=d/(maxn+1);a[len++]=c;}a[len++]=d;}BigNum(const char *s){int t,k,index,L,i;memset(a,0,sizeof(a));L=strlen(s);len=L/dlen;if(L%dlen)len++;index=0;for(int i=L-1;i>=0;i-=dlen){t=0;k=i-dlen+1;if(k<0)k=0;for(int j=k;j<=i;j++)t=t*10+s[j]-‘0‘;a[index++]=t;}}BigNum(const BigNum memset(a,0,sizeof(a));for(int i=0;i
POJ 2084 卡特兰数+高精度模板,布布扣,bubuko.com

