首先我们高精度加法算出前10W个数。。。

然后把所有的前40位搞出来建成trie树,于是就变成了模板题了。。。

说一下。。。这题要是直接建出来son[tot][10]会MLE。。。所以。。。建trie树的时候得像建普通树一样add_edge

QAQ卡内存sxbk

 /**************************************************************
Problem: 2492
User: rausen
Language: C++
Result: Accepted
Time:2836 ms
Memory:71184 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm>
#include <map> using namespace std;
const int radix = 1e8;
const int Mx = 1e5;
const int N = ; struct fib {
int l, x[]; inline void zero() {
memset(x, , sizeof(x));
l = ;
}
inline void one() {
memset(x, , sizeof(x));
x[] = l = ;
}
inline int& operator [] (const int &p) {
return x[p];
} inline fib operator + (const fib &b) const {
static fib res;
static int i;
res.zero(), res.l = max(l, b.l);
for (i = ; i < res.l; ++i) {
res[i] += x[i] + b.x[i];
res[i + ] = res[i] / radix, res[i] %= radix;
}
if (res[res.l]) ++res.l;
return res;
}
} a, b, c; char ch[]; struct edge {
int next, to, t;
edge() {}
edge(int _n, int _to, int _t) : next(_n), to(_to), t(_t) {}
} e[N];
int first[N], tot, pos[N], cnt_T; inline void add_edge(const int &x, const int &y, const int &t) {
e[++tot] = edge(first[x], y, t), first[x] = tot;
} inline int find(const int &p, const int &t) {
static int x;
for (x = first[p]; x; x = e[x].next)
if (e[x].t == t) return e[x].to;
return ;
} #define Pos pos[p]
inline void trie_insert(char* ch, const int &len, const int &P) {
static int p, i, t;
for (p = i = ; i < len; ++i) {
t = ch[i] - '';
if (!find(p, t)) {
add_edge(p, ++cnt_T, t);
p = cnt_T;
} else p = find(p, t);
if (Pos == ) Pos = P + ;
}
} inline void trie_query(char *ch, const int &len) {
static int p, i, t;
for (p = i = ; i < len; ++i) {
t = ch[i] - '';
if ((p = find(p, t)) == ) {
puts("-1");
return;
}
}
printf("%d\n", Pos - );
}
#undef Pos int main() {
int i, j, tot_len, tmp, len, Q, icase;
a.one(), b.one();
trie_insert("", , );
for (i = ; i < Mx; ++i) {
c = b + a, a = b, b = c, len = c.l;
tot_len = sprintf(ch, "%d", c[len - ]);
for (j = ; j <= len; ++j) {
tmp = sprintf(ch + tot_len, "%08d", c[len - j]);
if ((tot_len += tmp) >= ) break;
}
tot_len = min(tot_len, );
trie_insert(ch, tot_len, i);
}
scanf("%d", &Q);
for (icase = ; icase <= Q; ++icase) {
scanf("%s", ch);
len = strlen(ch);
printf("Case #%d: ", icase);
trie_query(ch, len);
}
return ;
}

BZOJ2492 Revenge of Fibonacci的更多相关文章

  1. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

  2. hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法

    Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...

  3. HDU4099 Revenge of Fibonacci(高精度+Trie)

    Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/ ...

  4. [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci

    题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) / ...

  5. HDU 4099 Revenge of Fibonacci Trie+高精度

    Revenge of Fibonacci Problem Description The well-known Fibonacci sequence is defined as following: ...

  6. UVA 12333 Revenge of Fibonacci

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. HDU 4099 Revenge of Fibonacci(高精度+字典树)

    题意:对给定前缀(长度不超过40),找到一个最小的n,使得Fibonacci(n)前缀与给定前缀相同,如果在[0,99999]内找不到解,输出-1. 思路:用高精度加法计算斐波那契数列,因为给定前缀长 ...

  8. HDU 4099 Revenge of Fibonacci (数学+字典数)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头 ...

  9. TZOJ 3820 Revenge of Fibonacci(大数+trie)

    描述 The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the F ...

随机推荐

  1. Python基础学习笔记(九)常用数据类型转换函数

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-variable-types.html 3. http://www ...

  2. AngularJS Protractor

    官网地址:http://www.protractortest.org/ 1. 预备环境 protractor 是一个 Node.js 程序,为了运行 protractor ,你首先需要 Node 环境 ...

  3. eclipse svn 忽略 target目录 等等... 我用的后边的方法 (转载)

    这个build失败的解决方案就是不要把你项目的 target目录放在src repository 里面,还有 .project 和 .classpath 最好也别放到src repository 里. ...

  4. netbeans环境的建立

    这是一个简单的实验,熟悉NetBeans的IDE环境的开发 首先下载一个NetBeans,可以在官网上下https://netbeans.org/downloads/index.html 要装NetB ...

  5. iOS - OC 与 Swift 互相操作

    前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...

  6. XP_版本

    1. Windows XP sp3 cd 和Windows XP sp3 cd vl的区别?VL的意思是大客户版,就是使用VL的KEY安装的系统是不需要激活的,不带VL的是安装完后需要激活的零售版 2 ...

  7. Vnc viewer与windows之间的复制粘贴

    用VNC连接到Linux之后,最纠结的问题就是无法复制粘贴.其实很简单,在Linux里面,打开一个终端,然后输入命令: vncconfig 之后,会弹出一个窗口 不要关闭那个小窗口 之后,就可以愉快的 ...

  8. Mvc4_Area的应用

    为什么需要分离? 我们知道MVC项目各部分职责比较清晰,相比较ASP.NET Webform而言,MVC项目的业务逻辑和页面展现较好地分离开来,这样的做法有许多优点,比如可测试,易扩展等等.但是在实际 ...

  9. Canu FAQ常见问题

    链接:Canu FAQ Q: What resources does Canu require for a bacterial genome assembly(细菌基因组组装)?   A mammal ...

  10. 基因组 de novo 组装原理

    Falcon软件的组装流程 为了错误校正,将原始子reads进行overlap 预组装和错误校正 错误校正后reads的overlap检测 overlap的过滤 从overlap构建图 从图构建con ...