HDU 1023 Train Problem II( 大数卡特兰 )
**链接:****传送门 **
题意:裸卡特兰数,但是必须用大数做
balabala:上交高精度模板题,增加一下熟悉度
/*************************************************************************
> File Name: hdu1023.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月11日 星期四 19时25分09秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
const int maxlen = 10000;
class HP{ public:
int len , s[maxlen];
HP(){ (*this) = 0; };
HP(int inte){ (*this) = inte; }; HP(const char *str){ (*this)=str; };
friend ostream & operator<<(ostream &cout,const HP &x);
HP operator = (int inte); HP operator = (const char*str);
HP operator * (const HP &b); HP operator - (const HP &b);
HP operator / (const HP &b); int Compare (const HP &b);
HP operator + (const HP &b);
};
ostream& operator <<(ostream & cout,const HP &x){
for(int i=x.len ; i>=1 ; i--) cout<<x.s[i]; return cout;
}
HP HP::operator = (const char *str){
len = strlen(str);
for(int i=1;i<=len;i++) s[i] = str[len-i]-'0';
return *this;
}
HP HP::operator = (int inte){
if(inte==0){ len = 1; s[1] = 0; return(*this); };
for(len = 0;inte>0;){ s[++len]=inte%10; inte/=10; };
return (*this);
}
HP HP::operator * (const HP &b){
int i,j;
HP c;
c.len = len + b.len;
for(i=1;i<=c.len;i++) c.s[i] = 0;
for(i=1;i<=len;i++) for(j=1;j<=b.len;j++) c.s[i+j-1] += s[i]*b.s[j];
for(i=1;i<c.len;i++){ c.s[i+1] += c.s[i]/10; c.s[i] %= 10; };
while(c.s[i]) { c.s[i+1] = c.s[i]/10 ; c.s[i] %= 10 ; i++; }
while(i>1 && !c.s[i]) i--; c.len = i;
return c;
}
HP HP::operator - (const HP &b){
int i,j; HP c;
for(i=1,j=0;i<=len;i++){
c.s[i] = s[i] - j; if(i<=b.len) c.s[i] -= b.s[i];
if(c.s[i]<0){ j=1; c.s[i]+=10; } else j = 0;
}
c.len = len; while(c.len>1 && !c.s[c.len]) c.len--;
return c;
}
int HP::Compare(const HP &y){
if(len>y.len) return 1;
if(len<y.len) return -1;
int i = len;
while( (i>1)&&( s[i]==y.s[i] ) ) i--;
return s[i]-y.s[i];
}
HP HP::operator / (const HP &b){
int i,j; HP d(0),c;
for(i=len;i>0;i--){
if( !(d.len==1 && d.s[1]==0) )
{ for( j = d.len; j>0;j--) d.s[j+1] = d.s[j]; ++d.len; }
d.s[1] = s[i]; c.s[i] = 0;
while( (j=d.Compare(b))>=0 )
{ d = d-b; c.s[i]++; if(j==0) break; }
}
c.len = len; while( (c.len>1)&&(c.s[c.len]==0) ) c.len--;
return c;
}
HP HP::operator + (const HP &b){
int i; HP c; c.s[1] = 0;
for(i = 1; i<=len || i<=b.len || c.s[i]; i++ ){
if( i<=len ) c.s[i] += s[i];
if( i<=b.len ) c.s[i] += b.s[i];
c.s[i+1] = c.s[i]/10; c.s[i] %= 10;
}
c.len = i-1; if( c.len == 0 ) c.len = 1;
return c;
}
int main(){
HP h[102];
h[0] = h[1] = 1;
for(int i=2;i<=100;i++){
for(int j=0;j<i;j++){
h[i] = h[i] + (h[j]*h[i-1-j]);
}
}
int n;
while(~scanf("%d",&n)){
cout<<h[n]<<endl;
}
return 0;
}
HDU 1023 Train Problem II( 大数卡特兰 )的更多相关文章
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- 1023 Train Problem II(卡特兰数)
Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
- Train Problem II(卡特兰数 组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
- Train Problem II(卡特兰数+大数乘除)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Train Problem II (卡特兰数+大数问题)
卡特兰数: Catalan数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) ...
- HDOJ 1023 Train Problem II 卡特兰数
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...
随机推荐
- github配置单个及多个sshkey的操作方法
一.配置单个sshkey 配置SSHKey命令操作: git --version //检验git是否装好了 cd / cd ~/.ssh //到master目录下 ll //展示所有文件 ssh-ke ...
- 训练1-o
给出2个N * N的矩阵M1和M2,输出2个矩阵相乘后的结果. Input 第1行:1个数N,表示矩阵的大小(2 <= N <= 100)第2 - N + 1行,每行N个数,对应M1的1行 ...
- 朴素贝叶斯(Naive Bayesian)
简介 Naive Bayesian算法 也叫朴素贝叶斯算法(或者称为傻瓜式贝叶斯分类) 朴素(傻瓜):特征条件独立假设 贝叶斯:基于贝叶斯定理 这个算法确实十分朴素(傻瓜),属于监督学习,它是一个常用 ...
- android生成sdk.jar 小工具
net.sf.fjep.fatjar_0.0.31.jar 生成jar的工具 把这个net.sf.fjep.fatjar_0.0.31.jar到Eclipse的plugins中,从启Eclipse.点 ...
- 【ACM-ICPC 2018 南京赛区网络预赛 E】AC Challenge
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个DP 设f[j]表示已经做的题的状态为j的情况下接着选能获得的最大分数. 显然是个倒推. 记忆化搜索一波 dfs(i,j) 表示 ...
- Java基础学习总结(63)——Java集合总结
数据结构是以某种形式将数据组织在一起的集合,它不仅存储数据,还支持访问和处理数据的操作.Java提供了几个能有效地组织和操作数据的数据结构,这些数据结构通常称为Java集合框架.在平常的学习开发中,灵 ...
- telnet允许root用户登录
默认情况下,linux不允许root用户以telnet方式登录linux主机,若要允许root用户登录,可采取以下3种方法之一: 1.修改login文件 redhat中对于远程登录的限制体现在/ ...
- 在IntelliJ IDEA中创建Maven多模块项目
在IntelliJ IDEA中创建Maven多模块项目 1,创建多模块项目选择File>New>Project 出现New Project窗口左侧导航选择Maven,勾选右侧的Create ...
- UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)
先从中找出性能最好的那个数, 在用钱比較少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #incl ...
- HDU 1171 Big Event in HDU(多重背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...