HDU5328.Problem Killer

题解:
首先如果a,b,c是等差数列,且b,c,d也是等差数列,那么a,b,c,d也是等差数列,这个结论等于等比数列也成立,所以只要对于每个i(i+2

#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
const int maxn=1e6+10;
int a[maxn];

int main(){
    int t;
    int n;
    //freopen("1002.in","r",stdin);
    //freopen("1001.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        if(n==1){
            printf("1\n"); 
            continue;
        }
        int ans=1;
        for(int i=0;i<n;){
            int count1=2;
            if((i+2)<n&&a[i]+a[i+2]==2*a[i+1])
                while((i+2)<n&&a[i]+a[i+2]==2*a[i+1]){
                    i++;
                    count1++;
                }
            else
                i++;
            ans=max(count1,ans);
        }
        for(int i=0;i<n;){
            int count1=2;
            if((i+2)<n&&(ll)a[i]*a[i+2]==(ll)a[i+1]*a[i+1])
                while((i+2)<n&&(ll)a[i]*a[i+2]==(ll)a[i+1]*a[i+1]){
                    i++;
                    count1++;
                }
            else
                i++;
            ans=max(count1,ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}

你可能感兴趣的:(HDU5328.Problem Killer)