hdu5328

题意:求最长的连续的等差 或者 等比序列

思路: 暴力,输入的时候将它们的差和比分别存在两个数组中

ps:此题动不动就超时 很无语, 必须用传统的输入输出, 不能加memset, 如果wa了

考虑下n==2时答案是否为2;

代码:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a) memset(a,0,sizeof(a))
#define ss(a,b) scanf("%d%d",&a,&b)
#define s(a) scanf("%d",&a)
#define INF 0x3f3f3f3f
#define w(a) while(a)
#define PI acos(-1.0)
#define LL long long
#define eps 10E-9
#define N 1000000 + 5
#define mod 100000000
using namespace std;
void mys(int& res)
{
    int flag=0;
    char ch;
    while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-'))
        if(ch==EOF)  res=INF;
    if(ch=='-')  flag=1;
    else if(ch>='0'&&ch<='9')  res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')  res=res*10+ch-'0';
    res=flag?-res:res;
}
void myp(int a)
{
    if(a>9)
        myp(a/10);
    putchar(a%10+'0');
}
/*************************THE END OF TEMPLATE************************/
double arr[N] = {0};
double a1[N] = {0};//from 1 to n-1
double a2[N] = {0};//from 1 to n-1
int main()
{
    int t,  n ,x ,y;
    s(t);
    w(t--){
        s(n);
        if(n == 2){
          ss(x,y);
          printf("2\n");
        }
        else{
        scanf("%lf",&arr[1]);
        int ans1 = -1, ans2  = -1, bg1 = 0, bg2 = 0;
        for(int i=2; i<=n; i++){
            scanf("%lf",&arr[i]);
            a1[i-1] = arr[i] - arr[i-1];
            a2[i-1] = (arr[i] / arr[i-1]);
            if(i>2){
                if(a1[i-1] == a1[i-2]) bg1 ++;
                if(a1[i-1] != a1[i-2] || i==n){
                ans1  = max(ans1,  bg1);
                bg1 = 0;
               }
               if(a2[i-1] == a2[i-2]) bg2 ++;
               if(a2[i-1] != a2[i-2] || i==n){
                ans2  = max(ans2,  bg2);
                bg2 = 0;
               }
            }
        }
        printf("%d\n", max(ans1, ans2) + 2);
        }
    }
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值