zoukankan
html css js c++ java
hdu1134大数+catalan数
//hdu1134大数+catalan数 #include<iostream> #include<string> #include<iomanip> #include<algorithm> using namespace std; #define MAXN 9999 #define DLEN 4 class BigNum{ private: int a[300]; int len; public: BigNum(){len = 1;memset(a,0,sizeof(a));} BigNum(const int b); BigNum(const BigNum & T); bool Bigger(const BigNum &) const; BigNum & operator=(const BigNum &); BigNum & Add(const BigNum &); BigNum & Sub(const BigNum &); BigNum operator+(const BigNum &) const; BigNum operator-(const BigNum &) const; BigNum operator*(const BigNum &) const; BigNum operator/(const int &) const; void Print(); }; BigNum::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); cout<<d / (MAXN + 1) * (MAXN + 1)<<endl; cout<<c<<endl; d = d / (MAXN + 1); a[len++] = c; } a[len++] = d; } BigNum::BigNum(const BigNum & T) : len(T.len) { int i; memset(a,0,sizeof(a)); for(i = 0 ; i < len ; i++) a[i] = T.a[i]; } bool BigNum::Bigger(const BigNum & T) const { int ln; if(len > T.len) return true; else if(len == T.len){ ln = len - 1; while(a[ln] == T.a[ln] && ln >= 0) ln--; if(ln >= 0 && a[ln] > T.a[ln]) return true; else return false; } else return false; } BigNum & BigNum::operator=(const BigNum & n) { len = n.len; memset(a,0,sizeof(a)); for(int i = 0 ; i < len ; i++) a[i] = n.a[i]; return *this; } BigNum & BigNum::Add(const BigNum & T) { int i,big; big = T.len > len ? T.len : len; for(i = 0 ; i < big ; i++) { a[i] = a[i] + T.a[i]; if(a[i] > MAXN) { a[i + 1]++; a[i] = a[i] - MAXN - 1; } } if(a[big] != 0) len = big + 1; else len = big; return *this; } BigNum & BigNum::Sub(const BigNum & T) { int i,j,big; big = T.len > len ? T.len : len; for(i = 0 ; i < big ; i++){ if(a[i] < T.a[i]){ j = i + 1; while(a[j] == 0) j++; a[j--]--; while(j > i) a[j--] += MAXN; a[i] = a[i] + MAXN + 1 - T.a[i]; } else a[i] -= T.a[i]; } len = big; while(a[len - 1] == 0 && len > 1) len--; return *this; } BigNum BigNum::operator*(const BigNum & T) const { BigNum ret; int i,j,up; int temp,temp1; for(i = 0 ; i < len ; i++){ up = 0; for(j = 0 ; j < T.len ; j++){ temp = a[i] * T.a[j] + ret.a[i + j] + up; if(temp > MAXN){ temp1 = temp - temp / (MAXN + 1) * (MAXN + 1); up = temp / (MAXN + 1); ret.a[i + j] = temp1; } else { up = 0; ret.a[i + j] = temp; } } if(up != 0) ret.a[i + j] = up; } ret.len = i + j; while(ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--; return ret; } BigNum BigNum::operator/(const int & b) const { BigNum ret; int i,down = 0; for(i = len - 1 ; i >= 0 ; i--){ ret.a[i] = (a[i] + down * (MAXN + 1)) / b; down = a[i] + down * (MAXN + 1) - ret.a[i] * b; } ret.len = len; while(ret.a[ret.len - 1] == 0) ret.len--; return ret; } void BigNum::Print() { int i; cout << a[len - 1]; for(i = len - 2 ; i >= 0 ; i--){ cout.width(DLEN); cout.fill('0'); cout << a[i]; } cout << endl; } int main() { BigNum x[110]; long n,i; x[1]=1; x[2]=2; x[3]=5; for(i=3;i<100;i++) { x[i+1]=x[i]*(4*i+2)/(i+2); } while(cin>>n&&n!=-1) { x[n].Print(); } return 0; }
查看全文
相关阅读:
Excel宏打开URL 特殊字符#变了
windows升级到1607后操作很卡顿的解决办法
打包解决方案后,安装时提示只能在IIS5.1以上运行解决方法
在CS代码页获取input输入框内肉----.net学习点滴
greenplum 6.7编译安装插件pxf
greenplum 6.7编译安装插件mysql_fdw
python3 + greenplum-spark-connector访问greenplum
centos7无cm安装hadoop+spark
hive实现update和delete功能
使得hivecli访问hive
原文地址:https://www.cnblogs.com/windmissing/p/2559898.html
最新文章
DataRow[]数组转换为DataTable
ORA-01439:要更改数据类型,则要修改的列必须为空
xml与DataSet互转
MD5加密汇总
c#处理图片格式的转换
POST提交方式
按长度截取字符串
C#生成.tlb文件初认识
根据配置的地址类调用第三方的接口
根据数据库表结构来整合插入、删除、更新语句
热门文章
尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。(原因系统是64位,oracle也是64位)
OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用 问题处理
[转]mysql到底使用收费版还是免费版?
VS加载项目时报错:尚未配置为Web项目.指定的本地IIS URL http://localhsst/..要打开项目,需要配置虚拟目录 。是否立即创建虚拟目录
windows下无法删除文件的问题
c# EncryptDES DecryptDES
C# 随机验证码
JS判定数字
C#连接SAP获取RFC函数数据 中文乱码变为#问题
ASP.NET使用COM组件调用OUTLOOK2016发送邮件
Copyright © 2011-2022 走看看