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)递推. ...
随机推荐
- NEFU 118
其实一道公式题: n!中素数i的幂为: [n/i]+[n/i^2]+[n/i^3]+[n/i^4]+...... #include <iostream> #include <cstd ...
- Android慎用layout嵌套, 尽量控制在5层下面java.lang.StackOverflowError
一.探寻原因 在一个复杂的layout嵌套较多layout的android界面.在Android 2.3.内存较低 的机型上,出现 java.lang.StackOverflowError 这个Exc ...
- POJ--1087--A Plug for UNIX【Dinic】网络最大流
链接:http://poj.org/problem? id=1087 题意:提供n种插座.每种插座仅仅有一个,有m个设备须要使用插座,告诉你设备名称以及使用的插座类型,有k种转换器.能够把某种插座类型 ...
- Hadoop之文件系统Shell
概述: 文件系统(FS)Shell包括各种类-Shell的命令.直接和Hadoop分布式文件系统(HDFS)交互,也支持对其它文件系统的支持.比如:本地文件系统FS,HFTP FS,S3 FS,和其它 ...
- Fibbonacci Number(杭电2070)
/*Fibbonacci Number Problem Description Your objective for this question is to develop a program whi ...
- kentico中提示Message: An invalid SQL query was used.
在调用CMSAbstractWebPart类的GetValue方法的时候出错. namespace CMS.PortalEngine.Web.UI{ /// <summary> /// B ...
- 机器学习 数据量不足问题----1 做好特征工程 2 不要用太多的特征 3 做好交叉验证 使用线性svm
来自:https://www.zhihu.com/question/35649122 其实这里所说的数据量不足,可以换一种方式去理解:在维度高的情况下,数据相对少.举一个特例,比如只有一维,和1万个数 ...
- notepad++ 查找引用(Find Reference)(适用于c c++及各类脚本比如lua、python等)
在程序开发过程中,程序员经常用到的一个功能就是查找引用(Find Reference),Visual Studio里面的对应功能是“查找所有引用”(Find All References). 我在使用 ...
- Java-MyBatis-杂项: MyBatis 中 in 的用法2
ylbtech-Java-MyBatis-杂项: MyBatis 中 in 的用法2 1.返回顶部 1. 一.简介 在SQL语法中如果我们想使用in的话直接可以像如下一样使用: select * fr ...
- JSP页面动态查询添加数据与分页数据显示
1 . <%@ page language="java" contentType="text/html; charset=UTF-8"%> < ...