1001, HDU 5327 Olympiad
Play a table check-in question. The degree of opening 4minFB ...
There should be a more optimized method, in order to hand speed without tle on the line ... = =
1002, HDU 5328 zzx and permutations
AP: Linear sequence
GP: equal-ratio sequence
The length of the maximum sequence of AP and GP is calculated by the ruler, then the maximal value can be obtained.
It is important to note that the equivalence is best used in a proportional way rather than in division, because the sample, like [9 6 4], produces a precision problem, and if you use 9*4==6*6 it will not be a problem. Of course, the resulting problem is that multiplying the words can cause an int overflow, so a long long is required to save a array.
Outputs 1 or 2 when an AP or GP sequence cannot form three elements;
#include <cstdio>#include<cstring>#include<iostream>#include<iostream>#include<cmath>#include<algorithm>using namespaceStd;typedefLong Longll;Const intMAXN =1000010; ll A[MAXN];intN;intAP () {intRET =2; intT1, T2, T3, S; S= T1 =0; T2=1; T3=2; while(1) { while(T3 < n && a[t3]-a[t2] = = a[t2]-A[t1]) {T1+ +, t2++, t3++; } if(T3 >=N) {ret= Max (ret, t3-s); Break; } ret= Max (ret, t3-s); S=T2; T1++; t2++; t3++; } returnret;}intGP ()//here Direct copy AP () Change a little condition can{ intRET =2; intT1, T2, T3, S; S= T1 =0; T2=1; T3=2; while(1) { //cout << a[t2] << "<< a[t3] <<" "<< a[t1] << Endl; while(T3 < n && a[t2]*a[t2] = = a[t3]*A[t1]) {T1+ +, t2++, t3++; } if(T3 >=N) {ret= Max (ret, t3-s); Break; } ret= Max (ret, t3-s); S=T2; T1++; t2++; t3++; } returnret;}intMain () {intT scanf"%d", &T); while(t--) {scanf ("%d", &N); for(inti =0; I < n; i++) scanf ("%lld", &A[i]); if(n = =1|| n = =2) {cout<< N <<Endl; Continue; } intAPs, GP; AP=AP (); GP=GP (); cout<< Max (APS, GP) <<Endl; } return 0;}
Cond...
Multi-School # #