SZU : A11 Sequence

系统 1542 0

Description

We are given a integer sequence, your job is find the length of the longest contiguous subsequence that is strictly increasing or strictly decreasing.

Input

  • First number , represent how many test cases.
  • For each test case the first number is .
  • Then  positive integers are followed, all of them are less than 101.

Output

For each test case output the answer in one line.

Sample Input

    
      3

3 1 1 1

3 1 2 3

4 4 3 2 1


    
  

Sample Output

    
      1

3

4
      


思路: 用2个数组存取递增递减序列,并且浪费点空间节省效率的方法去做。

      
         1
      
       #include<stdio.h>


      
         2
      
      
        int
      
      
         main()


      
      
         3
      
      
        {


      
      
         4
      
      
        int
      
       i,j,test,num,len,A[
      
        50
      
      ],B[
      
        50
      
      ],C[
      
        50
      
      
        ];


      
      
         5
      
           scanf(
      
        "
      
      
        %d
      
      
        "
      
      ,&
      
        test);


      
      
         6
      
      
        for
      
      (i=
      
        0
      
      ;i<test;i++
      
        )


      
      
         7
      
      
            {


      
      
         8
      
               scanf(
      
        "
      
      
        %d
      
      
        "
      
      ,&
      
        num);


      
      
         9
      
      
        for
      
      (j=
      
        0
      
      ;j<num;j++
      
        )


      
      
        10
      
                   scanf(
      
        "
      
      
        %d
      
      
        "
      
      ,&
      
        C[j]);


      
      
        11
      
               A[
      
        0
      
      ]=
      
        1
      
      
        ;


      
      
        12
      
               B[
      
        0
      
      ]=
      
        1
      
      
        ;


      
      
        13
      
      
        for
      
      (j=
      
        1
      
      ;j<num;j++
      
        )


      
      
        14
      
      
                {


      
      
        15
      
      
        if
      
      (C[j]>C[j-
      
        1
      
      
        ])


      
      
        16
      
      
                    {


      
      
        17
      
                       A[j]=A[j-
      
        1
      
      ]+
      
        1
      
      
        ;


      
      
        18
      
                       B[j]=
      
        1
      
      
        ;


      
      
        19
      
      
                    }


      
      
        20
      
      
        if
      
      (C[j]<C[j-
      
        1
      
      
        ])


      
      
        21
      
      
                    {


      
      
        22
      
                       A[j]=
      
        1
      
      
        ;


      
      
        23
      
                       B[j]=B[j-
      
        1
      
      ]+
      
        1
      
      
        ;


      
      
        24
      
      
                    }


      
      
        25
      
      
        if
      
      (C[j]==C[j-
      
        1
      
      
        ]){


      
      
        26
      
                       A[j]=
      
        1
      
      
        ;


      
      
        27
      
                       B[j]=
      
        1
      
      
        ;


      
      
        28
      
      
                    }


      
      
        29
      
      
                }


      
      
        30
      
      
        for
      
      (j=
      
        0
      
      ,len=
      
        0
      
      ;j<num;j++
      
        )


      
      
        31
      
      
                {


      
      
        32
      
      
        if
      
      (A[j]>len)    len=
      
        A[j];


      
      
        33
      
      
        if
      
      (B[j]>len)      len=
      
        B[j];


      
      
        34
      
      
                }


      
      
        35
      
               printf(
      
        "
      
      
        %d\n
      
      
        "
      
      
        ,len);


      
      
        36
      
      
            }


      
      
        37
      
      
        return
      
      
        0
      
      
        ;


      
      
        38
      
       }
    

 

    
       
    
  

SZU : A11 Sequence


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论