HDU 5328(Problem Killer-暴力)

Problem Killer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1535    Accepted Submission(s): 576

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

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

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

2015 Multi-University Training Contest 4

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5416 5415 5414 5413 5412

暴力

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int a[MAXN],b[MAXN];
double c[MAXN];
int main()
{
//	freopen("B.in","r",stdin);

	int n,T;
	cin>>T;
	while (T--)
	{
		cin>>n;
		For(i,n) scanf("%d",&a[i]);
		int ans=min(2,n);
		For(i,n-1) b[i]=a[i]-a[i+1];
		int p=2;
		Fork(i,2,n-1) if (b[i]==b[i-1]) ans=max(ans,++p);else p=2; 

		For(i,n-1) c[i]=(double)a[i]/(double)a[i+1];
		p=2;
		Fork(i,2,n-1) if (fabs(c[i]-c[i-1])<1e-8) ans=max(ans,++p);
		else p=2; 

		cout<<ans<<endl;

	}

	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-18 18:33:28

HDU 5328(Problem Killer-暴力)的相关文章

HDU 5328 Problem Killer(尺取法)

You are a "Problem Killer", you want to solve many problems. Now you have nn problems, the ii-th problem's difficulty is represented by an integer aiai (1≤ai≤1091≤ai≤109). For some strange reason, you must choose some integer ll and rr (1≤l≤r≤n1

hdu 5328 Problem Killer(杭电多校赛第四场)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重要的一个就是解题关键:如a[i-2],a[i-1],a[i],a[i+1]这个序列.a[i-2],a[i-1],a[i]是等差数列,a[i-1],a[i],a[i+1]也是等差数列.那么a[i-2],a[i-1],a[i],a[i+1]就是等差数列.  2. 等比数列也是一样的~~只要根据这个性质就

HDU 5328 Problem Killer(水题)

题意:给一个序列,要找一个等差或等比的连续子序列,求其最长的长度. 思路:扫两遍,判断等差或等比即可.从左往右扫,维护一个滑动窗口,考虑新加进来的数,如果满足了要求,则更新长度,否则只留最后两个数字,其他删掉,接着继续考虑下一个数字.等比也是如此,只是要注意精度的问题. 别人的代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int MAX = 1e6+2; 4 int arr[MAX]; 5 6 int main(vo

HDU 5328 Problem Killer

题意:给一段序列,求连续的子序列中最长的等差数列或者等比数列的长度. 解法:O(n)的扫两遍一次判等差一次判等比就好了. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<limits.h> #include<time.h&

HDU 5328(2015多校4)-Problem Killer(水题)

题目地址:HDU 5328 题意:在一个长度为n的序列中取出连续的k个数,让这k个数组成等差数列或者等比数列,问这样的k最大可以是多少. Ps:注意用double搞,因为等比数列求公比相除可能为小数. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #i

HDU 3699 A hard Aoshu Problem (暴力搜索)

题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(相同的字符串进行相同的数字替换), 替换后的三个数进行四则运算要满足左边等于右边,求有几种解法. Sample Input 2 A A A BCD BCD B Sample Output 5 72 eg:ABBDE   ABCCC   BDBDE :令 A = 1, B = 2, C = 0, D = 4, E = 5 12245 + 12000 = 24245: 注意没有前导零!! #include<stdio.h>

HDU 4831 Scenic Popularity 暴力模拟

Scenic Popularity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 340    Accepted Submission(s): 110 Problem Description 临近节日,度度熊们最近计划到室外游玩公园,公园内部包括了很多的旅游景点区和休息区,由于旅游景点很热门,导致景点区和休息区都聚集了很多人.所以度度熊

hdu 4737 二分或暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4737 Problem Description There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)

HDU 4910 Problem about GCD

Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop