C - Train Problem II——卡特兰数
题目
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.
input
The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.
output
For each test case, you should output how many ways that all the trains can get out of the railway.
Sample Input
1
2
3
10
Sample Output
1
2
5
16796
思路:
仔细一看,就是让你求卡特兰数,只不过这个数的范围大了点,会爆long long ,所以要用数组来进行存储。这道题的核心应该就是让求大数对一个较小的数的乘法和除法。
而这个乘法和除法(因为是对一个较小的数的操作)所以就是简单的模拟我们平常手算对数的乘法和除法。
具体代码实现如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[2005];
void mu(int k)
{
int c=0;
for(int i=1;i<=2000;i++)
{
int u=a[i]*k+c;
a[i]=u%10;
c=u/10;
} }
void chu(int k)
{
int c=0;
for(int i=2000;i>=1;i--)
{
int u=a[i]+c;
a[i]=u/k;
c=u%k*10;
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,0,sizeof(a));
a[1]=1;
for(int i=n+1;i<=2*n;i++)
{
mu(i);
}
for(int i=1;i<=n+1;i++)
{
chu(i);
}
int flog=0;
for(int i=2000;i>=1;i--)
{
if(a[i]!=0)
{
flog=1;
}
if(flog==1)
{
printf("%d",a[i]);
}
}
printf("\n");
}
return 0;
}
C - Train Problem II——卡特兰数的更多相关文章
- hdu1032 Train Problem II (卡特兰数)
		
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
 - HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)
		
题目链接:https://cn.vjudge.net/problem/HDU-1023 题意 卡特兰数的应用之一 求一个长度为n的序列通过栈后的结果序列有几种 思路 一开始不知道什么是卡特兰数,猜测是 ...
 - HDU 1023 Train Problem II (卡特兰数,经典)
		
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
 - HDOJ 1023 Train Problem II 卡特兰数
		
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...
 - 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 (大数卡特兰数)
		
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - Train Problem II(卡特兰数 组合数学)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
 - (母函数 Catalan数 大数乘法 大数除法)  Train Problem II   hdu1023
		
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 ...
 
随机推荐
- JS数据结构——队列
			
创建一个自己的类来表示一个队列 function Queue() { //这里写属性和方法 } 首先需要一个用于存储队列中元素的数据结构,可以用数组 let items = [] 接下来声明一些队列可 ...
 - 105道BAT最新Java面试题(MySQL+Redis+nginx+ookeeper+MongoDB)
			
MySQL面试题 1. 主键 超键 候选键 外键 2.数据库事务的四个特性及含义 3. 视图的作用,视图可以更改么? 4. drop,delete与truncate的区别 5. 索引的工作原理及其种类 ...
 - python基础入门 字典
			
字典 字典---->dict 字典是无序的,可变的 关联性强 键值对 键:使用不可变的数据类型(可哈希),键是唯一的 值:可以任意 定义一个字典 dic = {}#定义字典  字典的增删改查 ...
 - Java 从入门到进阶之路(十五)
			
在之前的文章我们介绍了一下 Java 中的接口,本章我们来看一下 Java 中类的多态. 在日常生活中,很多意思并不是我们想要的意思,如下: 1.领导:“你这是什么意思?” 小明:“没什么意思,意思意 ...
 - 使用saltstack自动部署K8S
			
使用saltstack自动部署K8S 一.环境准备 1.1 规划 1. 操作系统 CentOS-7.x-x86_64. 2. 关闭 iptables 和 SELinux. 3. 所有节点的主机名和 I ...
 - 【Java必修课】好用的Arrays.asList也有这三个坑
			
好用的asList 在开发或写测试用例的过程中,经常会用到Arrays.asList()这个方法,可以快速方便地将数组转化成一个List.例如: List<String> list = A ...
 - git  本地代码 切换远程分支
			
公司之前代码使用的是gitlab,后来换成腾讯的工峰,所以需要切换远程不支,所以在原代码上切换即可. 在原项目打开git bash命令,打开后会显示本地的原始分支 打开后 添加新的远程分支,红色字体为 ...
 - Hack the Zico2 VM (CTF Challenge)
			
下载链接: Download this VM here: https://download.vulnhub.com/zico/zico2.ova 端口扫描: ╰─ nmap -p1-65535 -sV ...
 - jar包要读取的资源文件路径问题
			
本地调试读取文件没有问题 获取 Thread.currentThread().getContextClassLoader().getPath() 读取文件 打jar包之后 获取的路径出错 不能读取文件 ...
 - Cross-Site Scripting:Reflected 跨站点脚本:获取