题目链接

BZOJ5300

题解

这题真的是很丧病,,卡高精卡到哭

我们设\(f[i]\)表示卸掉前\(i\)个环需要的步数

那么

\[f[i] = 2*f[i - 2] + f[i - 1] + 1
\]

直接高精递推不仅\(MLE\)而且\(TLE\)

然后就要用到数学求通项公式,或者打表找规律

\[f[n] = \lfloor \frac{2^{n + 1}}{3} \rfloor
\]

高精乘低精就可以过了

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,B = 100000000,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct NUM{
LL s[100000],len;
NUM(){cls(s); len = 0;}
void out(){
if (!len){putchar('0'); return;}
printf("%lld",s[len - 1]);
for (int i = len - 2; i >= 0; i--)
printf("%08lld",s[i]);
}
}F;
inline void operator *=(NUM& a,const int& b){
LL tmp,carry = 0;
for (int i = 0; i < a.len; i++){
tmp = 1ll * a.s[i] * b + carry;
a.s[i] = tmp % B;
carry = tmp / B;
}
while (carry) a.s[a.len++] = carry % B,carry /= B;
}
inline NUM operator /(const NUM& a,const int& b){
NUM c;
c.len = a.len;
LL tmp,carry = 0;
for (int i = a.len - 1; i >= 0; i--){
tmp = a.s[i] + 1ll * carry * B;
if (tmp < b) c.s[i] = 0,carry = tmp;
else c.s[i] = tmp / b,carry = tmp % b;
}
//if (carry) c = c + 1;
while (c.len && !c.s[c.len - 1]) c.len--;
return c;
}
int main(){
int T = read();
while (T--){
int n = read() + 1,bin = 1 << 30;
F.len = 1; F.s[0] = 1;
int tmp = n / 30,t = n % 30;
while (tmp--) F *= bin;
while (t--) F *= 2;
F = F / 3;
F.out(); puts("");
}
return 0;
}

BZOJ5300 [Cqoi2018]九连环 【dp + 高精】的更多相关文章

  1. 洛谷P4608 [FJOI2016]所有公共子序列问题 【序列自动机 + dp + 高精】

    题目链接 洛谷P4608 题解 建个序列自动机后 第一问暴搜 第二问dp + 高精 设\(f[i][j]\)为两个序列自动机分别走到\(i\)和\(j\)节点的方案数,答案就是\(f[0][0]\) ...

  2. [CEOI2007]树的匹配Treasury(树形DP+高精)

    题意 给一棵树,你可以匹配有边相连的两个点,问你这棵树的最大匹配时多少,并且计算出有多少种最大匹配. N≤1000,其中40%的数据答案不超过 108 题解 显然的树形DP+高精. 这题是作为考试题考 ...

  3. [P1005][NOIP2007] 矩阵取数游戏 (DP+高精)

    我不会高精…… 也不会DP…… 这道题即考高精又考DP…… 我要死了 给一个不是高精的代码(当然不能满分) #include<cstdio> #include<iostream> ...

  4. 矩阵取数问题(dp,高精)

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n×mn \times mn×m的矩阵,矩阵中的每个元素ai,ja_{i,j}ai,j​均为非负整数.游戏规则如下: 每次取数时须从每行各取走 ...

  5. BZOJ1089 [SCOI2003]严格n元树 【dp + 高精】

    Description 如果一棵树的所有非叶节点都恰好有n个儿子,那么我们称它为严格n元树.如果该树中最底层的节点深度为d (根的深度为0),那么我们称它为一棵深度为d的严格n元树.例如,深度为2的严 ...

  6. bzoj 1089: [SCOI2003]严格n元树【dp+高精】

    设f[i]为深度为i的n元树数目,s为f的前缀和 s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种 写个高精就行了,好久没写WA了好几次-- #incl ...

  7. 矩阵取数游戏 2007年NOIP全国联赛提高组(dp+高精)

    矩阵取数游戏 2007年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description [问题描述]帅帅经常跟 ...

  8. 2019.01.02 bzoj5300: [Cqoi2018]九连环(fft优化高精+快速幂)

    传送门 题意不好描述(自己看样例解释) 首先可以推出一个递推式:fn=fn−1+2fn−2+1f_n=f_{n-1}+2f_{n-2}+1fn​=fn−1​+2fn−2​+1 然后可以构造两个等式: ...

  9. # BZOJ5300 [CQOI2018]九连环 题解 | 高精度 FFT

    今天做了传说中的CQOI六道板子题--有了一种自己很巨的错觉(雾 题面 求n连环的最少步数,n <= 1e5. 题解 首先--我不会玩九连环-- 通过找规律(其实是百度搜索)可知,\(n\)连环 ...

随机推荐

  1. datatable中reload和load的区别

    ajax.reload()用于datatable表某个数据的变化而重新加载 ajax.url(url).load() 用于切换url时,datatable重新获取数据,加载.

  2. python__高级 : Property 的使用

    一个类中,假如一个私有属性,有两个方法,一个是getNum , 一个是setNum 它,那么可以用 Property 来使这两个方法结合一下,比如这样用  num = property(getNum, ...

  3. C语言字符篇(一)字符串转换函数

      #include <stdlib.h>   double atof(const char *nptr);  将字符串转换成双精度浮点数 int atoi(const char *npt ...

  4. POJ:2739-Sum of Consecutive Prime Numbers(尺取)

    Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27853 Ac ...

  5. [BZOJ3631][JLOI2014]松鼠的新家(树链剖分)

    [BZOJ3631] 树剖模板题了, Code #include <cstdio> #include <algorithm> #define MID int mid=(l+r) ...

  6. spark streaming的应用

    今天我们讲spark streaming的应用,这个是实时处理的,类似于Storm以及Flink相关的知识点, 说来也巧,今天的自己也去听了关于Flink的相关的讲座,可惜自己没有听得特别清楚,好像是 ...

  7. PHP.26-TP框架商城应用实例-后台3-商品修改、删除

    商品修改{修改页一般与添加页有百分之九十的相似度} create($_POST,Model::MODEL_UPDATE):系统内置的数据操作包括Model::MODEL_INSERT(或者1)和Mod ...

  8. 变量存储类型(auto static extern)

    auto 动态存储类型变量(函数内部变量存储默认为 auto型) auto只用于函数内部定义,单片机在执行这个函数时为它分配内存地址,当函数执行完毕返回后,auto变量会被销毁,再次进入这个函数时,它 ...

  9. Struts2---配置文件讲解及简单登录示例

    bean 用于创建一个JavaBean实例 constant 用于Struts2默认行为标签 <!-- 配置web默认编码集,相当于HttpServletRequest.setChartacte ...

  10. BZOJ 5004: 开锁魔法II

    比较显然 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; i ...