解题报告 之 HDU5328 Problem Killer
Description
You are a "Problem Killer", you want to solve many problems.
Now you have
problems, the
-th problem's difficulty is represented by an integer
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
(
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
).
For some strange reason, you must choose some integer
and
(
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/01bc1273e88dd7ef9389d487cf619486.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
), and solve the problems between the
-th and the
-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
Now you have
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/094f0c54ab74a17baaa3bd2c27e2cbb6.png)
For some strange reason, you must choose some integer
![](https://i-blog.csdnimg.cn/blog_migrate/01bc1273e88dd7ef9389d487cf619486.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/01bc1273e88dd7ef9389d487cf619486.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/01bc1273e88dd7ef9389d487cf619486.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
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
, indicating the number of cases.
For each test case, the first line contains a single integer
, the second line contains
integers
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d9efe1ce21b2c8d4b2797ef8bce8879a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e3f420d38eb1b6e230fcbf29a6d432c3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/de4d65270f7bda852eceea5f14ef2a8c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/22875e86171e5b60dcb243b59de3c487.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/05551fa6371615e3eee3221cf9b1dec1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
For each test case, the first line contains a single integer
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d9efe1ce21b2c8d4b2797ef8bce8879a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e3f420d38eb1b6e230fcbf29a6d432c3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/de4d65270f7bda852eceea5f14ef2a8c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/43f98a79cd719cbbc21b0987c23c4b74.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/22875e86171e5b60dcb243b59de3c487.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/05551fa6371615e3eee3221cf9b1dec1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/650fe694514e5180a7e3ec913d76adf0.png)
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
题目大意:给你一个数字序列,求其中 最长等差数列 和 最长等比数列 两者中更长者的长度。
分析:从左到右扫一遍,遇到无法继续接着构造等差/等比数列的数字就更新一下最大值,重新开始构造新的。注意重新开始构造不需要从上一个数列的第二个数字开始,因为没有意义,到了当前数字之后 差值/比例还是不一样;而是应该从上一个数列的最后一个作为起点,用新的差值/比例构造。
上代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
int kase;
cin >> kase;
while(kase--)
{
int n;
scanf( "%d", &n );
int AP = INF;
double GP = INF;
int APnum = 2, GPnum = 2;
int APmax = 0, GPmax = 0;
int pre, now;
scanf( "%d", &pre );
if(n == 1)
{
printf( "1\n" );
continue;
}
for(int i = 1; i < n; i++)
{
scanf( "%d", &now );
int APtem = now - pre;
double GPtem = (double)now / pre;
if(AP != APtem)
{
APmax = max( APmax, APnum );
APnum = 2;
AP = APtem;
}
else
{
APnum++;
}
if(GP != GPtem)
{
GPmax = max( GPmax, GPnum );
GPnum = 2;
GP = GPtem;
}
else
{
GPnum++;
}
pre = now;
}
GPmax = max( GPmax, GPnum );
APmax = max( APmax, APnum );
printf( "%d\n", max( GPmax, APmax ) );
}
return 0;
}