POJ 2084
第一题组合数学题。可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理。(高精度)
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string> using namespace std; const int maxn = 200;
struct bign {
int len, s[maxn]; bign() {
memset(s, 0, sizeof(s));
len = 1;
} bign(int num) {
*this = num;
} bign(const char* num) {
*this = num;
} bign operator =(int num) { //直接以整数赋值
char s[maxn];
sprintf(s, "%d", num);
*this = s;
return *this;
} bign operator =(const char* num) { //以字符串赋值
len = strlen(num);
for(int i = 0; i < len; i++)
s[i] = num[len - i - 1] - '0';
return *this;
} string str() const { //将bign转化成字符串
string res = "";
for(int i = 0; i < len; i++)
res = (char) (s[i] + '0') + res;
if(res == "")
res = "0";
return res;
} bign operator +(const bign& b) const { //重载+号运算
bign c;
c.len = 0;
for(int i = 0, g = 0; g || i < max(len, b.len); i++) {
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x % 10;
g = x / 10;
}
return c;
} void clean() { //去掉前到0
while(len > 1 && !s[len - 1])
len--;
} bign operator *(const bign& b) { //重载*号运算
bign c;
c.len = len + b.len;
for(int i = 0; i < len; i++)
for(int j = 0; j < b.len; j++)
c.s[i + j] += s[i] * b.s[j];
for(int i = 0; i < c.len - 1; i++) {
c.s[i + 1] += c.s[i] / 10;
c.s[i] %= 10;
}
c.clean();
return c;
} bign operator -(const bign& b) { //重载-号运算
bign c;
c.len = 0;
for(int i = 0, g = 0; i < len; i++) {
int x = s[i] - g;
if(i < b.len)
x -= b.s[i];
if(x >= 0)
g = 0;
else {
g = 1;
x += 10;
}
c.s[c.len++] = x;
}
c.clean();
return c;
} bool operator <(const bign& b) const { //重载<号运算
if(len != b.len)
return len < b.len;
for(int i = len - 1; i >= 0; i--)
if(s[i] != b.s[i])
return s[i] < b.s[i];
return false;
} bool operator >(const bign& b) const { //重载>号运算
return b < *this;
} bool operator <=(const bign& b) { //重载<=号运算
return !(b > *this);
} bool operator ==(const bign& b) { //重载>=号运算
return !(b < *this) && !(*this < b);
} bign operator +=(const bign& b) { //重载+=号运算
*this = *this + b;
return *this;
}
}; istream& operator >>(istream &in, bign& x) { //重载输入运算符
string s;
in >> s;
x = s.c_str();
return in;
} ostream& operator <<(ostream &out, const bign& x) { //重载输出运算符
out << x.str();
return out;
} bign ans[210]; void initial(){
ans[2]=1;
ans[4]=2;
for(int i=5;i<=200;i++){
ans[i]=ans[i-2]+ans[i-2];
for(int j=3;j<i;j++){
ans[i]=ans[i]+ans[j-2]*ans[i-j];
}
}
} int main(){
initial();
int n;
while(scanf("%d",&n),n!=-1){
cout<<ans[2*n]<<endl;
}
return 0;
}
POJ 2084的更多相关文章
- POJ 2084 Catalan数+高精度
POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...
- POJ 2084 Game of Connections
卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...
- (组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_2084 ...
- POJ 2084 Game of Connections(卡特兰数)
卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...
- POJ 2084 Catalan
Game of Connections Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8772 Accepted: 43 ...
- poj——2084 Game of Connections
Game of Connections Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8664 Accepted: 42 ...
- POJ 2084 Game of Connections 卡特兰数
看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1 h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) ( ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- POJ 2137
水,dp[i][j][k],设为当前为i个牛,在它喜欢的j个位置,而第一个牛在k个位置,很明显了,其实不过是枚举. #include <iostream> #include <cst ...
- POJ 1201 & HDU1384 & ZOJ 1508 Intervals(差分约束+spfa 求最长路径)
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:htt ...
- linux块设备的IO调度算法和回写机制
************************************************************************************** 參考: <Linux ...
- Android App 内存泄露之Thread
Thread 内存泄露 线程也是造成内存泄露的一个重要的源头.线程产生内存泄露的主要原因在于线程生命周期的不可控. 1.看一下以下是否存在问题 <span style="white-s ...
- VC 对话框程序加入工具栏button图标及其buttontooltip
注意:本人使用VC++2010开发环境进行測试. 在使用VC开发对话框程序时不像开发单文档程序和多文档程序那么方便,非常多资源都须要自己手动加入.近期在开发一个程序时.想尝试在对话框程序里面加入 工具 ...
- 2015.04.24,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 34
1.no fatigue indefatigable([indi'fætigәb(ә)l] adj. 不知疲倦的)来自faigue,in-是反义词缀:后缀-able表示able to be,因此ind ...
- Hello The World! —— 致我们无悔的IT之旅
感谢IT,让我有了这么可爱活泼的伙伴. 有了KsCla,Coming,lhx_QAQ,tututu,AB_ever,Fat-zhang,wka,lhm这些伙伴神犇的陪伴,我的OI历程不至于那么枯燥无味 ...
- bzoj1588: [HNOI2002]营业额统计(splay)
1588: [HNOI2002]营业额统计 题目:传送门 题解: 复习splay所以来刷个水... 题目描述不是特别清楚:应该是找第i天以前一个最小的营业额和第i天做差的最小值作为第i天的最小波动值 ...
- DB-MySQL:MySQL 连接的使用
ylbtech-DB-MySQL:MySQL 连接的使用 1.返回顶部 1. Mysql 连接的使用 在前几章节中,我们已经学会了如何在一张表中读取数据,这是相对简单的,但是在真正的应用中经常需要从多 ...
- 7.gcc的使用
什么是gcc gcc编译器(GNU C Compiler) 现在我们所说的 gcc 是 GUN Compiler Collection的缩写,可以支持多种语言编译,比如 C,C++,Java, pas ...