码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj 5328 Problems killer

时间:2015-08-05 06:27:22      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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     }

 

hdoj 5328 Problems killer

标签:

原文地址:http://www.cnblogs.com/blueprintf/p/4703559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!