Problem Solving report HDU5328 problem Killer

Source: Internet
Author: User

Problem Solving report HDU5328 problem Killer

Description

You is a "problem Killer", you want to solve many problems.
Now we have Problems, the -th problem ' s difficulty is represented by an integer ( ).
For some strange reason, you must choose some integer and ( ), 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 what many problems can you solve at the most?

You can find the definitions of APS 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 .

< Span style= "" > Span style= "" > < Span class= "mn" id= "mathjax-span-83" style= "" >

Output

For each test case, output one line with a single integer, representing the answer.

Sample Input

Sample Output


title: give you a sequence of numbers to find the longest arithmetic progression and the longest geometric series the length of the elder.
analysis: Sweep from left to right, encountered unable to continue the construction of the linear/geometric series number will update the maximum value, re-start the construction of new. Note that restarting the construct does not need to start with the second number of the previous sequence, because it has no meaning, the difference/scale is not the same after the current number, but rather it should be constructed from the last of the previous sequence as a starting point and with a new difference/scale.
on the code:
#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 = in F;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! = Apte m) {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);p rintf ("%d\n", Max (Gpmax, Apmax));} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Problem Solving report HDU5328 problem Killer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.