Revenge of Fibonacci Problem Description The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the Fibonacci number F(n).  This sequence has been studied since the publication of Fibonacci's book Liber Abaci. So…
Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输出-1: 思路:直接使用数组模拟加法,再用Trie树插入查找即可:但是一般使用new Trie()的代码都是MLE的.反而我之前写的,直接得到数组大小的maxnode版本的内存可以接受:并且还有一点就是前40位的精度问题:由于是自己计算出来的finboncci数列,并不是系统给的,所以1的进位不会形成很长…
最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others)Total Submission(s): 1582    Accepted Submission(s): 356 Problem Description The well-know…
题意:对给定前缀(长度不超过40),找到一个最小的n,使得Fibonacci(n)前缀与给定前缀相同,如果在[0,99999]内找不到解,输出-1. 思路:用高精度加法计算斐波那契数列,因为给定前缀长度不超过40,所以高精度计算时每次只需保留最高60位,每次将得到的值插入到字典树中,使得树上每个节点只保留最小的n值.查询输出字典树结点的值. #include<cstdio> #include<cstring> #include<iostream> #define MAX…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头几位数字,如果不存在则输出-1. 题解:明明说好的不超过40,但是在建字典数的时候不加i<41就超内存了,杭电你是想咋地,害的我比较好多人的代码,一点一点试出来的. AC代码: #include <iostream> #include <cstdio> #include <…
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时,保存的位数过少,就会导致低位误差,累积起来就可能导致前40位产生错误,解决办法是提高精度. #include<iostream> #include<cstring> #include<string> #include<cstdio> using namespa…
Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others) Total Submission(s): 2582    Accepted Submission(s): 647 Problem Description The well-known Fibonacci sequence is defined as following: Here w…
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take…
大水题 #include<time.h> #include <cstdio> #include <iostream> #include<algorithm> #include<math.h> #include <string.h> #include<vector> #include<queue> typedef long long int ll; using namespace std; ll f[]; int…
Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others)Total Submission(s): 3218    Accepted Submission(s): 821 Problem Description The well-known Fibonacci sequence is defined as following: Here we…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3755 Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others)Total Submission(s): 914    Accepte…
题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) //UVa12333 - Revenge of Fibonacci //Accepted 0.250s //#define _XIENAOBAN_ #include<iostream> #include<cstring> #define MAXS 0xffffff #define CIN…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4099 要用c++交哦, G++ MLE 不是很懂,先粘上慢慢学习 代码: #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define N 100 struct node { int ID; node *next[];…
描述 The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the Fibonacci number F(n).This sequence has been studied since the publication of Fibonacci's book Liber Abaci. So far, many properties of this sequence ha…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A, f[2] = B),通过这条式子f[n] = f[n-1] + f[n-2],问 C 是否在这条 new Fibonacci sequence 内.(1 <= A, B, C <= 1 000 000 000) 首先,要想到 C 有可能是 A 或者 B,这种情况也是属于在这个序列范围内的. 还…
//  继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your tas…
题目:给定一个长度为40的数字,问其是否在前100000项fibonacci数的前缀 因为是前缀,容易想到字典树,同时因为数字的长度只有40,所以我们只要把fib数的前40位加入字典树即可.这里主要讨论下怎么得到fib数的前40位. 首先,因为没可能每一项的fib都求出来的了.空间都存不下来.所以,只能够缩小规模,有个明显的道理,用每个fib的前60项相加取前40即可.为什么呢?因为没有后效性,后面的项相加不会影响到前40项.就是你有40--60这些项来缓冲就够了,这些才是主要的进位项.后面的相…
高精度 trie 暴力预处理出前100000个fibonacci数,将每个数的前40位数字串插入到trie中,记录每个结点最早可以由哪个数字串到达. 然后依次回答询问即可. 存fibonacci数的数组当然要滚动起来. 时限是10秒.本机试着卡了常数后跑了18秒(这个高精度写法好像本来就很慢),干脆交一波,UVA上7s AC ↑for循环i+=4 和直接一个register跑出来一样快,果然WC2017那道题只能在特定机子上做吗233 ↑本机CPU是Intel I5-4590 #include<…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18217    Accepted Submission(s): 6120 Problem Description Given a list of phone numbers, determine if it is consistent in the sense th…
统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 34909    Accepted Submission(s): 13109 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己…
http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里将模式串s[1……len]的每一个[i,len]的子串都插入,这样就可以满足条件.还要注意如果两个子串都为同一个模式串的子串,不能重复计数.可以用一个id数组装上一次是哪个串的id,如果id相同就不要重复计数了. #include <cstdio> #include <algorithm&g…
首先我们高精度加法算出前10W个数... 然后把所有的前40位搞出来建成trie树,于是就变成了模板题了... 说一下...这题要是直接建出来son[tot][10]会MLE...所以...建trie树的时候得像建普通树一样add_edge QAQ卡内存sxbk /************************************************************** Problem: 2492 User: rausen Language: C++ Result: Accep…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.$F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n >…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie的数据结构中增加一个存储到当前节点字符串出现的次数,在插入的过程中维护即可. code: #include <cstdio> #include <cstring> ; struct TrieNode { int num; // 遍历到该结点形成的字符串出现的次数 TrieNode* n…
Problem Description Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4099 思想很容易想到 就是预处理出前10w个的fib数,然后建树查询 建树时只用前40位即可,所以在计算时只用截取前60位 但是我在截取时总是出错 后来看了别人的代码改了一下就对了 不过还是不知道为什么那样是对的 更改地方在代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstrin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) whic…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12952    Accepted Submission(s): 4331 Problem Description A Fibonacci sequence…
Problem C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1196    Accepted Submission(s): 371 Problem Description 度熊手上有一本神奇的字典,你可以在它里面做如下三个操作: 1.insert : 往神奇字典中插入一个单词 2.delete: 在神奇字典中删除所有前缀等于…