HDU 1134 卡特兰数 大数乘法除法
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?
3
-1
5
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int n;
#define BASE 10000
#define UNIT 4
#define FORMAT "%04d" class BigNum{
public:
int a[20];
int length;
BigNum(const int k){ //用小于BASE的k初始化大数
memset(a, 0, sizeof(a));
a[0] = k;
length = 1;
}
BigNum(){
memset(a, 0, sizeof(a));
length = 0;
}
BigNum operator * (const BigNum & B){
BigNum ans;
int i,j,up=0,num;
for(i=0; i<length; i++){
up = 0; //每次循环都要初始化为0
for(j=0; j<B.length; j++){
num = up + a[i] * B.a[j] + ans.a[i+j];
up = num / BASE;
num = num % BASE;
// cout << num << endl;
ans.a[i+j] = num;
}
// cout << up << endl;
if(up > 0)
ans.a[i+j] = up;
}
ans.length = i+j;
while(ans.a[ans.length -1] == 0 && ans.length > 1)
ans.length--;
return ans;
}
BigNum operator /(const int & k) const{ // k < BASE, 对此题适用
BigNum ans;
int down=0,i,num;
for(i=length-1; i>=0; i--){
num = ( (down * BASE) + a[i] ) / k;
down = ( (down * BASE) + a[i] ) % k;
ans.a[i] = num;
}
ans.length = length;
while(ans.a[ans.length-1] == 0 && ans.length > 1)
ans.length -- ;
return ans;
}
void print(){
printf("%d", a[length-1]);
for(int i=length-2; i>=0; i--)
printf(FORMAT,a[i]);
}
}; //f(n) = C(2n,n)/(n+1)
int main(){
BigNum nums[101];
nums[1] = BigNum(1);
nums[2] = BigNum(2);
nums[3] = BigNum(5);
for(int i=4; i<=100; i++){
nums[i] = nums[i-1] * (4*i-2)/(i+1);
}
int n;
while(scanf("%d", &n), n>0){
nums[n].print();
printf("\n");
}
return 0;
}
HDU 1134 卡特兰数 大数乘法除法的更多相关文章
- 2014年百度之星程序设计大赛 - 初赛(第一轮) hdu Grids (卡特兰数 大数除法取余 扩展gcd)
题目链接 分析:打表以后就能发现时卡特兰数, 但是有除法取余. f[i] = f[i-1]*(4*i - 2)/(i+1); 看了一下网上的题解,照着题解写了下面的代码,不过还是不明白,为什么用扩展g ...
- hdu-1130(卡特兰数+大数乘法,除法模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...
- hdu 1130,hdu 1131(卡特兰数,大数)
How Many Trees? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1134 Game of Connections(卡特兰数+大数模板)
题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...
- (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- hdu 1023 卡特兰数《 大数》java
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Buy the Ticket HDU 1133 卡特兰数应用+Java大数
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 【hdoj_1133】Buy the Ticket(卡特兰数+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元 ...
随机推荐
- Rule Or WorkFlow
The main value of a Workflow engine is that it makes it possible to customize the flows through some ...
- 实现Linux下的U盘(USB Mass Storage)驱动
如何实现Linux下的U盘(USB Mass Storage)驱动 版本:v0.7 How to Write Linux USB MSC (Mass Storage Class) Driver Cri ...
- 将文件放到Android模拟器的SD卡中的两种解决方法
两种方式:一.窗口界面操作1.打开DDMS页面2.打开File Explorer页,如果没有,在Window --> Show View -->File Explorer3.一般就在mnt ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- Windows上安装Xampp后通过命令行进入MariaDB
题外话:读<MYSQL必知必会>,书中让我找个数据库服务器练手,我就去下了个Xampp,由于看的08年网易上的动态网站开发,那个时候Xampp中的m代表MYSQL,后来通过命令行进入MYS ...
- 安装 SQL Server 2008 R2 的硬件和软件要求(转)
以下各部分列出了安装和运行 SQL Server 2008 R2 的最低硬件和软件要求.有关 SharePoint 集成模式下的 Analysis Services 的要求的详细信息,请参阅硬件和软件 ...
- flume-采集报错
h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...
- hdu 5615 Jam's math problem(判断是否能合并多项式)
方法一:由十字相乘相关理论我们能知道,如果要有p,k,q,m,那么首先要有解,所以b*b-4*a*c要>0,然而因为p,k,q,m是正整数,所以代表x1,x2都是有理数,有理数是什么鬼呢?就是解 ...
- 用Windows Live Writer 2012发博客
一.软件准备: 最新版的是Windows Live Writer 2012,但是不提供单独的安装包,它是和微软其它软件一起的(包括MSN.Window Move Maker等),软件大小为131M,官 ...
- VMware虚拟机与主机联通及配置上网
vmware版本:10.0.0 build-1295980,安装redhat enterprise linux 5.8 一.物理机与虚拟机联通,但不联网 1.虚拟网络VMnet1设置: 此时,物理主机 ...