bzoj2822: [AHOI2012]树屋阶梯
咦,这里有好多东西https://en.wikipedia.org/wiki/Catalan_number
每个矩形最多贡献一个拐角
枚举左上角的点和那个拐角是一个矩形
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} struct LL {
const static int N = , base = ;
int da[N], n; void init(int n) {
this->n = n;
memset(da, , sizeof(da[]) * n);
} void clear_zero() {
while(n && !da[n-]) n--;
} LL operator * (const int &rhs) const {
static LL c;
c.init(n + );
for(int i = ; i < c.n; i++) {
if(i < n) c.da[i] += da[i] * rhs;
c.da[i+] += c.da[i] / base;
c.da[i] %= base;
}
c.clear_zero();
return c;
} void print() const {
if(n == ) putchar('');
else for(int i = n - ; i >= ; i--) {
putchar(da[i] + '');
}
}
}res; const int LIM = , N = ; int mi[LIM+], primes[N], tot;
bool flag[LIM+]; void get_prime(int n) {
for(int i = ; i <= n; i++) {
if(!flag[i]) primes[tot] = i, mi[i] = tot++;
for(int j = ; j < tot; j++) {
int k = primes[j];
if(i * k > n) break;
flag[i * k] = ;
if(i % k == ) break;
}
}
} int num[N]; void add(int x, int sign) {
for(int i = , k; k = primes[i], k * k <= x; i++) {
while(x % k == ) {
num[i] += sign;
x /= k;
}
}
if(x ^ ) num[mi[x]] += sign;
}
int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int n; scanf("%d", &n);
get_prime(n * ); for(int i = n * ; i > n; i--) add(i, );
for(int i = n; i > ; i--) add(i, -);
add(n + , -); res.da[] = res.n = ;
for(int i = ; i < tot; i++) {
while(num[i]--) res = res * primes[i];
} res.print(); return ;
}
bzoj2822: [AHOI2012]树屋阶梯的更多相关文章
- bzoj2822[AHOI2012]树屋阶梯(卡特兰数)
2822: [AHOI2012]树屋阶梯 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 879 Solved: 513[Submit][Status] ...
- BZOJ2822[AHOI2012]树屋阶梯——卡特兰数+高精度
题目描述 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营.小龙分配的树屋建立在一颗高度为N+1尺(N为 ...
- BZOJ2822:[AHOI2012]树屋阶梯(卡特兰数,高精度)
Description 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营.小龙分配的树屋建立在一颗高度为 ...
- [bzoj2822][AHOI2012]树屋阶梯 (卡特兰数+分解质因数+高精度)
Description 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营.小龙分配的树屋建立在一颗高度为 ...
- [BZOJ2822]:[AHOI2012]树屋阶梯(卡特兰数)
题目传送门 题目描述 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营.小龙分配的树屋建立在一颗高度为N ...
- bzoj3907 网格 & bzoj2822 [AHOI2012]树屋阶梯——卡特兰数+高精度
题目:bzoj3907:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 bzoj2822:https://www.lydsy.com/Jud ...
- bzoj 3907 网格 bzoj2822 [AHOI2012]树屋阶梯——卡特兰数(阶乘高精度模板)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 https://www.lydsy.com/JudgeOnline/problem.p ...
- BZOJ 2822: [AHOI2012]树屋阶梯 [Catalan数 高精度]
2822: [AHOI2012]树屋阶梯 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 779 Solved: 453[Submit][Status] ...
- [AHOI2012]树屋阶梯 题解(卡特兰数)
[AHOI2012]树屋阶梯 Description 暑假期间,小龙报名了一个模拟野外生存作战训练班来锻炼体魄,训练的第一个晚上,教官就给他们出了个难题.由于地上露营湿气重,必须选择在高处的树屋露营. ...
随机推荐
- ubuntu1404下Apache2.4错误日志error.log路径位置
首先打开/etc/apache2路径下的apache2.conf文件,找到ErrorLog如下 ErrorLog ${APACHE_LOG_DIR}/error.log 这里{APACHE_LOG_D ...
- 测试functional的bind以及相关功能
注:在VS2010 UPDATE1下测试通过 /*测试functional的bind以及相关功能*/ #include <iostream> #include <functional ...
- 使用APPLICATION制作缓存,转存一下,有一段写的还可以。
public sealed class CacheManager { private HttpApplicationState appPool = null; /// <summar ...
- >炫酷的计时器效果Canvas绘图与动画<
>炫丽的计时器效果Canvas绘图与动画< 虽然我是学习java的,但是因为最近使用html5的关系,多学习了一下前端知识. 现在,我要介绍的计时器是十分炫酷的,使用画布完成. 喜欢htm ...
- sae的kvdb使用注意
之前没仔细看,原来sae的kvdb使用一定要先调用初始化函数 $kv = new SaeKV(); $kv->init();//必须使用 $kv->set('index', $data);
- odoo 错误 Resource interpreted as Stylesheet but transferred with MIME type application/x-css:
odoo8 页面内容显示一半, web 控制台显示错误 Resource interpreted as Stylesheet but transferred with MIME type ap ...
- 趣味C程序100.1 .2 绘制正弦曲线
说明:1.本问题来源于<C语言经典.趣味.实用程序设计编程百例精解>,所有程序为本人自己编写.与原程序不同之处作有标记. 2.本系列所有程序均使用codeblocks编译,操作系统为Win ...
- java答疑
问 什么是 Java 的字节码? 答 它是程序的一种低级表示,可以运行于 Java 的虚拟机.将程序抽象为字节码可以保证 Java 程序员的 代码能够运行在各种设备之上. 问 Java 允许整型溢出并 ...
- RAC oracle删除数据库
24:site2-DMS1:~ # su - oracleoracle@site2-DMS1:~> sqlplus / as sysdba SQL*Plus: Release 11.2.0.3. ...
- 【POJ1743】不可重叠最长重复子串
题意:求一个字符串里两个不重叠的最长重复子串 代码如下: #include<cstdio> #include<cstdlib> #include<cstring> ...