http://acm.hdu.edu.cn/showproblem.php?pid=5328
Problem Killer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 983 Accepted Submission(s): 375
Problem Description
You are a "Problem Killer", you want to solve many problems.
Now you have n problems, the i -th problem's difficulty is represented by an integer ai ( 1≤ai≤109 ).
For some strange reason, you must choose some integer l and r ( 1≤l≤r≤n ), and solve the problems between the l -th and the r -th, and these problems' difficulties must form an AP (Arithmetic Progression) or a GP (Geometric Progression).
So how many problems can you solve at most?
You can find the definitions of AP and GP by the following links:
https://en.wikipedia.org/wiki/Arithmetic_progression
https://en.wikipedia.org/wiki/Geometric_progression
Now you have n problems, the i -th problem's difficulty is represented by an integer ai ( 1≤ai≤109 ).
For some strange reason, you must choose some integer l and r ( 1≤l≤r≤n ), and solve the problems between the l -th and the r -th, and these problems' difficulties must form an AP (Arithmetic Progression) or a GP (Geometric Progression).
So how many problems can you solve at most?
You can find the definitions of AP and GP by the following links:
https://en.wikipedia.org/wiki/Arithmetic_progression
https://en.wikipedia.org/wiki/Geometric_progression
Input
The first line contains a single integer
T
, indicating the number of cases.
For each test case, the first line contains a single integer n , the second line contains n integers a1,a2,⋯,an .
T≤104,∑n≤106
For each test case, the first line contains a single integer n , the second line contains n integers a1,a2,⋯,an .
T≤104,∑n≤106
Output
For each test case, output one line with a single integer, representing the answer.
Sample Input
2 5 1 2 3 4 6 10 1 1 1 1 1 1 2 3 4 5
Sample Output
4 6
Author
XJZX
Source
求最大的一段区间长度,里面的数要么是等比数列,要么是等差数列。特例:n=1,输出1.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define sf scanf
#define LL long long
long long a[2000000];
LL n;
int main()
{
LL T;
sf("%lld",&T);
while(T--)
{
sf("%lld",&n);
for(LL i = 0;i<n;i++)
sf("%lld",a+i);
if(n==1){puts("1");continue;}
LL t1 = 2,t2 = 2;
LL ans = 2;
for(LL i =2;i<n;i++)
{
if(a[i]+a[i-2]==a[i-1]+a[i-1]) t1++;
else t1 = 2;
if(a[i]*a[i-2]==a[i-1]*a[i-1]) t2++;
else t2 = 2;
ans = max(ans,max(t1,t2));
}
printf("%lld\n",ans);
}
}