hdu 1023 Train Problem II

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1212

Train Problem II

Description

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.

SampleInput

1
2
3
10

SampleOutput

1
2
5
16796

卡特兰数。。

$ f(n) = f(n-1)*(n*4-2)/(n-1)$

  1 #include<algorithm>
  2 #include<iostream>
  3 #include<cstdlib>
  4 #include<cstring>
  5 #include<cassert>
  6 #include<cstdio>
  7 #include<vector>
  8 #include<string>
  9 #include<map>
 10 #include<set>
 11 using std::cin;
 12 using std::max;
 13 using std::cout;
 14 using std::endl;
 15 using std::string;
 16 using std::istream;
 17 using std::ostream;
 18 #define sz(c) (int)(c).size()
 19 #define all(c) (c).begin(), (c).end()
 20 #define iter(c) decltype((c).begin())
 21 #define cls(arr,val) memset(arr,val,sizeof(arr))
 22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
 23 #define rep(i, j, n) for (int i = j; i < (int)(n); i++)
 24 #define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
 25 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
 26 #define pb(e) push_back(e)
 27 #define mp(a, b) make_pair(a, b)
 28 struct BigN {
 29     typedef unsigned long long ull;
 30     static const int Max_N = 2010;
 31     int len, data[Max_N];
 32     BigN() { memset(data, 0, sizeof(data)), len = 0; }
 33     BigN(const int num) {
 34         memset(data, 0, sizeof(data));
 35         *this = num;
 36     }
 37     BigN(const char *num) {
 38         memset(data, 0, sizeof(data));
 39         *this = num;
 40     }
 41     void clear() { len = 0, memset(data, 0, sizeof(data)); }
 42     BigN& clean(){ while (len > 1 && !data[len - 1]) len--;  return *this; }
 43     string str() const {
 44         string res = "";
 45         for (int i = len - 1; ~i; i--) res += (char)(data[i] + '0');
 46         if (res == "") res = "0";
 47         res.reserve();
 48         return res;
 49     }
 50     BigN operator = (const int num) {
 51         int j = 0, i = num;
 52         do data[j++] = i % 10; while (i /= 10);
 53         len = j;
 54         return *this;
 55     }
 56     BigN operator = (const char *num) {
 57         len = strlen(num);
 58         for (int i = 0; i < len; i++) data[i] = num[len - i - 1] - '0';
 59         return *this;
 60     }
 61     BigN operator + (const BigN &x) const {
 62         BigN res;
 63         int n = max(len, x.len) + 1;
 64         for (int i = 0, g = 0; i < n; i++) {
 65             int c = data[i] + x.data[i] + g;
 66             res.data[res.len++] = c % 10;
 67             g = c / 10;
 68         }
 69         return res.clean();
 70     }
 71     BigN operator * (const BigN &x) const {
 72         BigN res;
 73         int n = x.len;
 74         res.len = n + len;
 75         for (int i = 0; i < len; i++) {
 76             for (int j = 0, g = 0; j < n; j++) {
 77                 res.data[i + j] += data[i] * x.data[j];
 78             }
 79         }
 80         for (int i = 0; i < res.len - 1; i++) {
 81             res.data[i + 1] += res.data[i] / 10;
 82             res.data[i] %= 10;
 83         }
 84         return res.clean();
 85     }
 86     BigN operator * (const int num) const {
 87         BigN res;
 88         res.len = len + 1;
 89         for (int i = 0, g = 0; i < len; i++) res.data[i] *= num;
 90         for (int i = 0; i < res.len - 1; i++) {
 91             res.data[i + 1] += res.data[i] / 10;
 92             res.data[i] %= 10;
 93         }
 94         return res.clean();
 95     }
 96     BigN operator - (const BigN &x) const {
 97         assert(x <= *this);
 98         BigN res;
 99         for (int i = 0, g = 0; i < len; i++) {
100             int c = data[i] - g;
101             if (i < x.len) c -= x.data[i];
102             if (c >= 0) g = 0;
103             else g = 1, c += 10;
104             res.data[res.len++] = c;
105         }
106         return res.clean();
107     }
108     BigN operator / (const BigN &x) const {
109         BigN res, f = 0;
110         for (int i = len - 1; ~i; i--) {
111             f *= 10;
112             f.data[0] = data[i];
113             while (f >= x) {
114                 f -= x;
115                 res.data[i]++;
116             }
117         }
118         res.len = len;
119         return res.clean();
120     }
121     BigN operator % (const BigN &x) {
122         BigN res = *this / x;
123         res = *this - res * x;
124         return res;
125     }
126     BigN operator += (const BigN &x) { return *this = *this + x; }
127     BigN operator *= (const BigN &x) { return *this = *this * x; }
128     BigN operator -= (const BigN &x) { return *this = *this - x; }
129     BigN operator /= (const BigN &x) { return *this = *this / x; }
130     BigN operator %= (const BigN &x) { return *this = *this % x; }
131     bool operator <  (const BigN &x) const {
132         if (len != x.len) return len < x.len;
133         for (int i = len - 1; ~i; i--) {
134             if (data[i] != x.data[i]) return data[i] < x.data[i];
135         }
136         return false;
137     }
138     bool operator >(const BigN &x) const { return x < *this; }
139     bool operator<=(const BigN &x) const { return !(x < *this); }
140     bool operator>=(const BigN &x) const { return !(*this < x); }
141     bool operator!=(const BigN &x) const { return x < *this || *this < x; }
142     bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
143     friend istream& operator >> (istream &in, BigN &x) {
144         string src;
145         in >> src;
146         x = src.c_str();
147         return in;
148     }
149     friend ostream& operator << (ostream &out, const BigN &x) {
150         out << x.str();
151         return out;
152     }
153 }A[101], B;
154 inline void init() {
155     A[1] = 1;
156     rep(i, 2, 101) {
157         B = 4 * i - 2;
158         A[i] = A[i - 1] * B / (i + 1);
159         B.clear();
160     }
161 }
162 int main() {
163 #ifdef LOCAL
164     freopen("in.txt", "r", stdin);
165     freopen("out.txt", "w+", stdout);
166 #endif
167     init();
168     std::ios::sync_with_stdio(false);
169     int n;
170     while (cin >> n) cout << A[n] << endl;
171     return 0;
172 }
View Code

 

转载于:https://www.cnblogs.com/GadyPu/p/4578972.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/397996.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

阿贝尔分部求和法的应用(二)

14.(阿贝耳定理) 设$\sum\limits_{n0}^{\infty}a_{n}s$. 则$\lim_{x\to 1-}\sum\limits_{n0}^{\infty}a_{n}x^{n}s$.证明: 容易看出$f(x)\sum\limits_{n0}^{\infty}a_{n}x^{n}$在$0 \leq x \leq 1$上一致收敛.由Cauchy收敛准则知,任意$\varepsilon>0$,存在$n$任意$p>0$有…

python中字母大小顺序,如何在Python中按字母顺序对unicode字符串排序?

Python sorts by byte value by default, which means comes after z and other equally funny things. What is the best way to sort alphabetically in Python?Is there a library for this? I couldnt find anything. Preferrably sorting should have language support…

Nginx自建CDN加速节点 实现DNS智能解析网站项目

如今&#xff0c;网站项目越来越多的会使用CDN加速&#xff0c;如果需要便捷一点的可以直接用第三方提供的CDN加速服务&#xff0c;比如百度CDN、七牛、又拍云、腾讯云、阿里云等等服务商都有提供这类服务。但是前提条件是需要一定的成本&#xff0c;以及网站域名是需要BA才可以…

字符串字典排序

把字符串以字典的展示形式排序&#xff0c;如把字符串abc,bad,aade,bdca排列成aade,abc,bad,bdca。 1.使用冒泡排序 (1) 相邻两数据两两比较&#xff0c;较大的放到后面&#xff0c;直到把最大的字符串放在最后一个位置。 (2) 从头开始再进行相邻数据两两比较&#xff0c;较大的…

OC2_点语法(属性关键字)

// // Dog.h // OC2_点语法(属性关键字) // // Created by zhangxueming on 15/6/16. // Copyright (c) 2015年 zhangxueming. All rights reserved. //#import <Foundation/Foundation.h>interface Dog : NSObject //属性关键字 //assgin(缺省)直接赋值 //基本类型 …

matlab中获取view,ios 怎么获取一个view的位置

ios 怎么获取一个view的位置以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;ios 怎么获取一个view的位置打开appstore进入应用&#xff0c;右上角的分享按钮(从右往左数第二个)&#xff0c;拷…

eureka需要替换吗_Spring Cloud Alibaba迁移指南1:零代码从Eureka迁移到Nacos

作者&#xff1a;得少&#xff0c;校对&#xff1a;周立。在本号首发&#xff0c;欢迎转载。Spring Cloud官方宣布Spring Cloud Netflix进入维护状态&#xff0c;后续不再会有新的功能已成为事实。作为开发者&#xff0c;如何使用极简的方式替换Netflix相关组件成为首要解决的问…

P1134 阶乘问题

题目描述 也许你早就知道阶乘的含义&#xff0c;N阶乘是由1到N相乘而产生&#xff0c;如&#xff1a; 12! 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 479,001,600 12的阶乘最右边的非零位为6。 写一个程序&#xff0c;计算N(1<N<50,000,000)阶乘的最右边的非零…

JAVA TCP通信练习

2019独角兽企业重金招聘Python工程师标准>>> 1、Server端 package com.hhdys.serviceimpl;import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.…

[转载]UEditor报错TypeError: me.body is undefined

本文转载来自&#xff1a; UEditor报错TypeError: me.body is undefined 今天在使用UEditor的setContent的时候报错&#xff0c;报错代码如下 TypeError: me.body is undefined 或 Uncaught TypeError: Cannot set property innerHTML of undefined 错误的原因是没有等UEditor创…

微服务架构下的身份认证

从单体应用架构到分布式应用架构再到微服务架构&#xff0c;应用的安全访问在不断的经受考验。为了适应架构的变化、需求的变化&#xff0c;身份认证与鉴权方案也在不断的变革。面对数十个甚至上百个微服务之间的调用&#xff0c;如何保证高效安全的身份认证&#xff1f;面对外…

php缓存注入,利用Thinkphp 5缓存漏洞实现前台Getshell

原标题&#xff1a;利用Thinkphp 5缓存漏洞实现前台Getshell*本文原创作者&#xff1a;WindWing&#xff0c;属于FreeBuf原创奖励计划&#xff0c;禁止转载000 背景网站为了实现加速访问&#xff0c;会将用户访问过的页面存入缓存来减小数据库查询的开销。而Thinkphp5框架的缓存…

mac版小达人点读包怎么安装_小达人点读笔扩容实战:16G变128G

随着小达人点读笔可以点读的童书越来越多&#xff0c;笔的容量就是个尴尬的问题&#xff1a;是处理掉手头的16G容量的旧点读笔&#xff0c;重新再买32G容量的新点记笔吗&#xff1f;如果32G容量也不够用怎么办&#xff1f;官方可没有更大容量的点读笔了。删除原先的点读内容&am…

序列化与反序列化(记住密码)

平常我们在做"记住密码"的时候,大多都是使用Cookie保存,然后设置保存的时间,但是上次Frame(窗体应用程序中)项目中,一直没找到怎么保存Cookie的方法,所以采用使用序列化的方法完成。 //序列化 1.引用命名空间 Using System.IO 2.登录成功序列化代码: if(cb_savepw…

看电子书的好处

省钱&#xff0c;基本上都能从网上下载到。 在电脑上和手机上都可以看&#xff0c;而且排除了对光源的要求&#xff0c;因为这些设备的屏幕本身自带光源。 做笔记时可以直接截屏保存&#xff0c;节省时间&#xff0c;或者是复制粘贴。 携带方便&#xff0c;要么下载到本地&a…

WorldWind源码剖析系列:可渲染对象类RenderableObject

RenderableObject是WorldWind中所有需要渲染的对象的父类&#xff0c;继承了接口IRenderable和Icomparable。其派生类体系如下所示。RenderableObject的成员如下所示。 RenderableObjectList也继承自RenderableObject。 接口Irenderable内部仅仅定义下面三个接口&#xff0c;分…

php table 下拉框,LayerUI的table 里面加 select 下拉框 – Fly社区-Mikel

先上效果图&#xff1a;直接上代码//添加样式&#xff1a;.table-select-icon{position:absolute;right:10px;line-height:34px;color:#d3d3d3}.table-select-selected dl{display:block}.table-select dl{position:absolute;left:0;padding:5px 0;z-index:999;min-width:100%;…

家里wifi网速越来越慢_家里的wifi信号不好?有了它再也不怕网速慢啦

夏天太热&#xff0c;就想宅在家里刷刷剧、打打游戏、看看新闻。可是网速却不好&#xff0c;看一会儿&#xff0c;卡一会儿&#xff0c;本来天气就热&#xff0c;这样更加烦躁&#xff01;这WiFi信号怎么会这么差&#xff1f;有什么好办法能解决这个问题呢&#xff1f;只要有了…