首先我们高精度加法算出前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. Xcode:Foundation框架找不到,或者是自动提示出现问题

    问题描述:Foundation框架找不到,或者是自动提示出现问题 之前的操作:手贱,不少心把编译器里面的源码改了 处理办法:清理缓存 缓存位置:点击桌面后,选择系统菜单栏:前往—电脑—硬盘—用户—ap ...

  2. GooglePlay_下载apk

    关键字:"APK Downloader" 方式: (1)."APK Downloader"网站在线下载(无需我们的GooglePlay账户信息,也就无需Goog ...

  3. css3,环绕圆环 loading,小组件

    一个loading的小组件, 给其他模块调用.先上图 type:cat type:ball 第一幅loading,老鼠是一个圆形的背景图片,已经转成base64. 小猫也是图片 也已经转成base64 ...

  4. 09 redo and undo

    本章提要-----------------------------------------------redo, undo 定义redo, undo 如何工作如何访问 redo, undo提交和回滚- ...

  5. poj3565Ants(KM-几何与图论的结合)

    链接 可以看出蓝的之和一定比红的之和要大,也就是说符合条件的匹配一定是权值最小的,所以二分图的最佳完美匹配..KM #include <iostream> #include<cstd ...

  6. Java的加密与解密

    package com.wangbo.util; import java.security.Key; import java.security.Security; import javax.crypt ...

  7. jQuery UI 实例 - 对话框(Dialog)(zhuan)

    http://www.runoob.com/jqueryui/example-dialog.html ************************************************* ...

  8. Velocity教程 (zhuan)

    http://blog.csdn.net/qq_25237663/article/details/52262532 ****************************************** ...

  9. 多路径(multi-path)安装测试实例

    1.确保安装以下的包: device-mapper device-mapper-multipath [root@nticket1~]# rpm -qa "*device*" dev ...

  10. MyBatis学习笔记(三) 关联关系

    首先给大家推荐几个网页: http://blog.csdn.net/isea533/article/category/2092001 没事看看 - MyBatis工具:www.mybatis.tk h ...