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 ...
随机推荐
- Docker下载tomcat
命令 下载tomcat docker pull tomcat //默认是latest版本具体可以到 hub.docker.com上查询 //如果想下其他版本以9.0.16示例那么: docker pu ...
- elasticsearch的快速安装
在阿里云服务器快速安装ElasticSearch 1.安装好java的jdk环境 2.使用wget下载elasticsearch安装包,wget的速度比较满,如果等不及的话,可以先下载好安装包再上传解 ...
- python将数据库修改,数据库操作同步到数据库中
*****************数据库迁移(同步)命令******************************** 1.python manage.py makemigrations 将数据库的 ...
- 《Java基础知识》Java常量的申明和使用
常量就是从程序开始运行到结束都不变的量.在 Java 程序设计中,使用关键字“final”来声明一个常量,例如下面的程序代码. 这里的 x 是一个常量,但是是在某个方法内的常量,也可以称为成员常量(作 ...
- Python高级应用程序设计任务
Python高级应用程序设计任务要求 用Python实现一个面向主题的网络爬虫程序,并完成以下内容:(注:每人一题,主题内容自选,所有设计内容与源代码需提交到博客园平台) 一.主题式网络爬虫设计方案( ...
- 阿里云服务器部署Tornado应用
本篇详细介绍tornado应用部署到阿里云服务器上的全过程. Tornado程序地址:github https://github.com/ddong8/ihasy.git 准备工作:阿里云服务器Cen ...
- vue.config.js的常用配置
const path = require('path') const glob = require('glob') const resolve = (dir) => path.join(__di ...
- Linux重要的服务讲述(1)
NFS 概述 NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS ...
- Cocos Creator 资源加载流程剖析【四】——额外流程(MD5 PIPE)
当我们将游戏构建发布到web平台时,勾选Md5 Cache选项可以开启MD5 Pipe,它的作用是给构建后的资源加上md5后缀,避免浏览器的缓存导致部分资源不是最新,因为使用了md5后缀后,当资源内容 ...
- 对于prim的一个有趣但有点奇怪的想法
prim算法找最小生成树适用于无向图,对于有向加权图会产生错误. 比如 1->2,8 1->3,8 2->3,4 3->2,3 最小生成树1->2->3 而不是3- ...