首先我们高精度加法算出前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. 一种json生成html的思路

    输入: [{ tag:"ul", attribute:{ class:"father6" }, property:{ className:"fathe ...

  2. XAF应用开发教程(七)外观控制模块

    很多时候,我们需要按照不同的条件显示不同的效果,在传统的软件开发中,我们会直接使用 控件名称.BackColor,Enable,Visible等属性进行控制. 如果一个业务对象在多处使用,要么我们会去 ...

  3. Web浏览器的缓存机制

    Web缓存的工作原理 所有的缓存都是基于一套规则来帮助他们决定什么时候使用缓存中的副本提供服务(假设有副本可用的情况下,未被销毁回收或者未被删除修改).这些规则有的在协议中有定义(如HTTP协议1.0 ...

  4. Div里面载入另一个页面的实现(取代框架)(AJax)(转)

    随着框架越来越不火了,HTML5就不对框架支持了,iframe也只有url了,Div就担当了此大任 DIV+CSS在页面部局确实也很让人满意,使用也更方便 今天突然遇到一个问题,那就是需要导入另一个页 ...

  5. Android最佳性能实践(三)——高性能编码优化

    在前两篇文章当中,我们主要学习了Android内存方面的相关知识,包括如何合理地使用内存,以及当发生内存泄露时如何定位出问题的原因.那么关于内存的知识就讨论到这里,今天开始我们将学习一些性能编码优化的 ...

  6. git 10.8

    git clone xxxx.git生成一个本地的文件夹acd agit checkout -b abcgit checkout mastergit pull然后数据全部由更新 但是是远程的更新 不能 ...

  7. ios app 支持 ipv6-only

    最近苹果公司发布声明:自今年6月1日开始,所有提交至苹果App Store的应用申请必须要兼容面向硬件识别和网络路由的最新互联网协议--IPv6-only标准. 那么问题来了,目前的app是否支持ip ...

  8. 如何设计一个RPC系统

    版权声明:本文由韩伟原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/162 来源:腾云阁 https://www.qclou ...

  9. Cache模拟器(CacheSim)

     最近写了一个Cache的模拟器,由于平时空余时间比较分散,前前后后用了一周多的时间,基本实现的Cache的模拟功能(通过读取trace文件得到相应的命中率),能够实现直接映射.全相联.组相联三种 ...

  10. sass less

    CSS 预处理器技术已经非常的成熟,而且也涌现出了越来越多的 CSS 的预处理器框架.本文向你介绍使用最为普遍的三款 CSS 预处理器框架,分别是 Sass.Less CSS.Stylus. 首先我们 ...