首先我们高精度加法算出前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. Codeforces Round #135 (Div. 2) E. Parking Lot 线段数区间合并

    E. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. 认识DOS

    实验一.认识DOS实验 专业 物联网工程  姓名 叶慧敏 学号 201306104139 一. 实验目的 (1)认识DOS: (2)掌握命令解释程序的原理: (3)掌握简单的DOS调用方法: (4)掌 ...

  3. iOS - UIViewController

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIViewController : UIResponder <NSCoding, UIAppearanceC ...

  4. win10系统更新补丁时进度条一直卡在0%不动的解决方案

    为了能够让win10系统更加安全稳定,很多用户都会时不时为自己的电脑安装补丁.不过,部分用户在为win10系统更新补丁时,却会遇到进度条一直卡在0%不动的问题.这该怎么办呢?下面,小编就告诉大家解决该 ...

  5. HIHO线段树(成段)

    #include <stdio.h> #define lson l,mid,id<<1 #define rson mid+1,r,id<<1|1 ; ],lazy[ ...

  6. alloc && afree

    #define ALLOCSIZE 10000 static char allocbuf[ALLOCSIZE]; static char *allocp = allocbuf; char *alloc ...

  7. jquery input选择弹框

    index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...

  8. 【服务器环境搭建-Centos】系统分区 待续

    df命令查看,显示/dev/vda,而不是sda或hda ,为什么? 虚拟机为了提升性能,一般使用virtio作为磁盘驱动,在虚拟机里面磁盘会显示成vda而不是传统的sda,有什么办法可以让他显示成s ...

  9. Mvc4_@RenderBody()和@RenderSection()

    @RenderBody():呈现子页的主体内容 @RenderSection():呈现特别的节部分. HelperResult RenderSection(string name, bool requ ...

  10. Windows BAT文件使用技巧[转载]

    首先,批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好象我们在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(notepad)等任 ...