hdu 5328 Problem Killer 2015多校联合训练赛4 简单题

Problem Killer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1281    Accepted Submission(s): 483


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  ( 1ai109 ).
For some strange reason, you must choose some integer  l  and  r  ( 1lrn ), 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

T104,n106
 

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


求等比或者等差数列中最长的区间的长度。直接贴解题报告了

http://blog.sina.com.cn/s/blog_15139f1a10102vof7.html




#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

long long num[1000001];

int main(){
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i = 0;i < n; i++)
            scanf("%I64d",&num[i]);
        int ans = min(n,2);
        int be = 0;
        for(int i = 2;i < n; i++){
            if(num[i] - num[i-1] == num[i-1] - num[i-2]){
            }
            else be = i-1;
            ans = max(ans,i-be+1);
        }
        be = 0;
        for(int i = 2;i < n; i++){
            if(num[i] * num[i-2] == num[i-1] * num[i-1]){
            }
            else be = i - 1;
            ans = max(ans,i-be+1);
        }
        printf("%d\n",ans);
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值