题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328
1 #include<stdio.h> 2 #include<algorithm> 3 typedef long long ll; 4 const int MAXN = 1e6+10; 5 ll a[MAXN]; 6 int main() 7 { 8 int lgt; int T; 9 int n; int tmp; 10 int i; 11 scanf("%d",&T); 12 while(T--){ 13 scanf("%d",&n); 14 for( i = 0; i < n; ++i){ 15 scanf("%I64d",&a[i]); 16 } 17 if( n == 2 ){ 18 printf("2\n"); 19 continue; 20 } 21 if( n == 1){ 22 printf("1\n"); 23 continue; 24 } 25 lgt = 2; 26 tmp = 2; 27 for( i = 2; i < n; ++i){ 28 if( ( a[i] - a[i-1] ) == ( a[i-1] - a[i-2] ) ){ 29 tmp++; 30 lgt = std::max(tmp,lgt); 31 } 32 else{ 33 lgt = std::max(tmp,lgt); 34 tmp = 2; 35 36 } 37 } 38 tmp = 2; 39 for( i = 2; i < n; ++i){ 40 if( ( (double)a[i] / (double)a[i-1] ) == ( (double)a[i-1] / (double)a[i-2] ) ){ 41 tmp++; 42 lgt = std::max(tmp,lgt); 43 } 44 else{ 45 lgt = std::max(tmp,lgt); 46 tmp = 2; 47 } 48 } 49 printf("%d\n",lgt); 50 } 51 }
时间: 2024-10-21 18:38:06