zoukankan      html  css  js  c++  java
  • hdoj5328【尺取】

    现在在队内赛(灰常艾斯比的队内赛),还是来写篇题解开心一下,23333.
    题意:
    就是问你找出一个最长的等比数列或者等差数列
    思路:
    一个等差的尺取,一个等比的尺取。2333,就这么过了,具体自己写吧。还是很容易实现的,注意数组要开1e6…还有long long….后面要做乘法。

    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    typedef __int64 LL;
    
    const int N=1e6+10;
    
    LL a[N];
    int n;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%d",&a[i]);
    
            if(n==1)
            {
                puts("1");
                continue;
            }
    
            int sum1;
            int sum2,temp;
            int s,t;
            LL x1,x2;
    
            temp=1;
            sum1=1;
            t=2;
            for(s=1;s<n;s++)
            {
                x1=a[t]-a[s];
                while(x1==(a[t+1]-a[t])&&t+1<=n)
                {
                    temp=t-s+2;
                    t++;
                }
                s=t-1;
                t=t+1;
                sum1=max(sum1,temp);
            }
    
            temp=sum2=2;
            t=2;
            for(s=1;s<n;s++)
            {
                while((a[t+1]*a[t-1])==(a[t]*a[t])&&t+1<=n)
                {
                    temp=t-s+2;
                    t++;
                }
                s=t-1;
                t=t+1;
                sum2=max(sum2,temp);
            }
            printf("%d
    ",max(sum1,sum2));
        }
    }
    /*
    10
    1 2 3 4 6 8 10 12 14 16
    13
    1 2 3 4 6 1 3 1 8 10 12 14 16
    */
  • 相关阅读:
    webpack
    react 原理
    jest
    input 自动获取焦点
    taro
    html5标签
    webpack
    每日日报
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934900.html
Copyright © 2011-2022 走看看