You have array a1, a2, ..., an. Segment [l, r] (1 ≤ lrn) is good if ai = ai - 1 + ai - 2, for all i (l + 2 ≤ ir).

Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).

Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Print the length of the longest good segment in array a.

Sample test(s)
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2

找出符合a[i] = a[i-1]+a[i-2]的最长长度

没有考虑0的状况。。。。。。蛋疼,长久没做CF了,坑成球了。。。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[100005],b[100005],len; int main()
{
int maxn,sum;
int i,n;
while(~scanf("%d",&n))
{
sum = 0;
for(i = 0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum == 0)
{
printf("%d\n",n);
continue;
}
if(n == 1)
{
printf("1\n");
continue;
}
if(n == 2)
{
printf("2\n");
continue;
}
len = 0;
int l,r,flag = 1;
for(i = 2; i<n; i++)
{
if(a[i-1]+a[i-2] == a[i])
b[len++] = 1;
else
b[len++] = 0;
}
maxn = 0;
l = 0;
r = 0;
for(i = 0; i<len; i++)
{
if(b[i] == 1)
{
if(flag)
{
l = i;
flag = 0;
}
else
r = i;
}
else
{
if(r-l+1>maxn && r!=l)
maxn = r-l+1;
flag = 1;
l = 0;
r = 0;
}
}
if(r-l+1>maxn && r!=l)
maxn = r-l+1;
printf("%d\n",maxn+2);
} return 0;
}

CF#213DIV2:B The Fibonacci Segment的更多相关文章

  1. cf B. The Fibonacci Segment

    http://codeforces.com/contest/365/problem/B #include <cstdio> #include <cstring> #includ ...

  2. CF 914 G Sum the Fibonacci —— 子集卷积,FWT

    题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能 ...

  3. 笔试算法题(11):Josephus环 & Fibonacci序列

    出题:Josephus Cycle,约瑟夫环问题.k个数字连成一个环,第一个数字为1.首先从1开始计数删除第m个数字:然后从上次被删除的数字的下一个数字开始计数,删除第m个数字:重复进行第二步直到只剩 ...

  4. 题解报告:poj 3070 Fibonacci

    题目链接:http://poj.org/problem?id=3070 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, a ...

  5. 题解报告:hdu 1848 Fibonacci again and again(尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  6. codeforces B. The Fibonacci Segment 解题报告

    题目链接:http://codeforces.com/problemset/problem/365/B 题目意思:简单来说,就是要找出最长的斐波纳契长度. 解决的方法不难,但是要注意更新左区间和右区间 ...

  7. HDU1250:Hat's Fibonacci

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  8. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  9. Codeforces Round #213 (Div. 2) B. The Fibonacci Segment

    #include <iostream> #include <algorithm> #include <vector> using namespace std; in ...

随机推荐

  1. 一些常用的Intent及intent-filter的信息

    Uri Action 功能 备注 geo:latitude,longitude Intent.ACTION_VIEW 打开地图应用程序并显示指定的经纬度   geo:0,0?q=street+addr ...

  2. poj2449 Remmarguts' Date【A*算法】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303855.html   ---by 墨染之樱花 [题目链接]:http://poj.org/ ...

  3. 使用LINQ的几个小技巧

    这里总结了这些技巧.介绍如何使用LINQ来: 初始化数组 在一个循环中遍历多个数组 生成随机序列 生成字符串 转换序列或集合 把值转换为长度为1的序列 遍历序列的所有子集 如果你在LINQ方面有心得也 ...

  4. sass基本语法

    sass是一种基于ruby语言开发的CSS预处理器.它可以使用变量,嵌套,混入,继承,运算,函数等编程语言具有的特性进行CSS的开发,使得CSS的开发变得简单粗暴清晰可维护. sass有两种后缀文件格 ...

  5. nvarchar and nchar

    Same: 1.store unicode charactor. 2. A charactor is stroed with 2 bytes. Different. 1. nchar  会自动填充数据 ...

  6. SQL Server:错误处理及事务控制

    目录: 解读错误信息 RAISERROR THROW 实例 使用 @@ERROR 使用 XACT_ABORT 使用TRY/CATCH 现实中的事务语句 删除 更新 银行取钱 解读错误信息 Msg 54 ...

  7. Clob对象转为字符串

    项目中遇到一个问题,对方公司把打印好的报表数据存到数据库中,实际上就是把html存在Oracle中,然后需要我们在社保系统里进行查询. 但是他们把数据存放在B数据库,而我们的社保系统用的数据库是B.A ...

  8. Mysql 外键设置

    MySql外键设置详解 (1) 外键的使用: 外键的作用,主要有两个:    一个是让数据库自己通过外键来保证数据的完整性和一致性    一个就是能够增加ER图的可读性    有些人认为外键的建立会给 ...

  9. JSON 数组格式

    JSON 数据格式 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人 ...

  10. 华为GVRP理解

    类似于CISCO的VTP 在大型的网络中,华为交换机之间的串联是很普遍的.一般交换机互联端口都是配置成Trunk,即允许透传多个VLAN的.对于用户来说,手工配置太麻烦.一个规模比较大的网络可能包含多 ...