Description
Input
Output
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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/maxichu/article/details/48026981