• ssu 488. Dales and Hills


    488. Dales and Hills

    Time limit per test: 0.5 second(s)
    Memory limit: 262144 kilobytes
    input: standard
    output: standard




    Let's consider a number sequence a1, ·s, aN. We call the continuous subsequence ai, ·s, aj, ·s, ak (1 ≤ i < j < kN) of the sequence a if at < at+1 for any it < j and at > at+1 for any jt < k. In this case we call the of the hill. Similarly, we call the continuous subsequence a if at > at+1 for any it < j and at < at+1 for any jt < k. In this case we call the of the dale.

    Compute the height of the highest hill and the depth of the deepest dale in the given sequence.

    Input

    The first line of the input file contains T (), the number of test cases. The test cases follow, occupying two lines each. The first of the two lines contains N (), the second the members of the sequence, separated by spaces. The sum of values of N over all test cases in the file does not exceed . The absolute values of the members of the sequences do not exceed .

    Output

    The output file should consist of T lines and each line should contain two integers, the height of the highest hill and the depth of the deepest dale. If there are no hills or no dales, output 0 in the corresponding position.

    Example(s)
    sample input
    sample output
    2
    10
    4 4 1 6 3 2 1 2 5 7
    10
    2 3 4 5 6 7 8 9 10 9
    
    1 3
    1 0
    
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstring>
    #include <set>
    #include <stack>
    #include <string>
    #define LL long long
    #define maxn 1000010
    #define mod 1000000007
    #define INF 2000000
    #define MAX 16000010
    #define eps 1e-6
    using namespace std;
    
    int a[maxn] ;
    int main()
    {
        int i ,m , tt , j , n ;
        int x , y , ii ,jj ,T ;
         //freopen("in.txt","r",stdin) ;
        // 直接枚举了,不过记得到了n要把 j--
        cin >> T ;
        while( T-- )
        {
            scanf("%d",&n) ;
            for( i = 0 ; i < n ;i++)
              scanf("%d",&a[i]) ;
              a[n] = -9999999 ;
              x = y = 0 ;
            for( i = 0 ; i < n ;i++ ) if(a[i] < a[i+1])
            {
                for( j = i+1 ; j < n ;j++)
                    if(a[j] >= a[j+1]) break ;
                    if(j==n)j-- ;
                    jj = j ;
                for( ; j < n ;j++ )
                    if(a[j] <= a[j+1]) break ;
                    if(j==n)j-- ;
                x = max(x,min(j-jj,jj-i)) ;
                i = j-1 ;// 这个记得要
            }
            a[n] = 9999999;
            for( i = 0 ; i < n ;i++ ) if(a[i] > a[i+1])
            {
                for( j = i+1 ; j < n ;j++)
                    if(a[j] <= a[j+1]) break ;
                    if(j==n)j-- ;
                    jj = j ;
                for( ; j < n ;j++ )
                    if(a[j] >= a[j+1]) break ;
                    if(j==n)j-- ;
                y = max(y,min(j-jj,jj-i)) ;
                i = j-1 ;
            }
            printf("%d %d
    ",x,y) ;
        }
        return 0 ;
    }
    
  • 相关阅读:
    理解消息循环和窗口过程(转)
    对话框和控件编程(转)
    俄罗斯方块
    男生女生配(抽屉原理)
    翻转吧,字符串
    数塔
    Pseudoprime numbers伪素数(快速幂+判定素数)
    shǎ崽 OrOrOrOrz
    As Easy As A+B
    求素数(筛选法)
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3596590.html
Copyright © 2020-2023  润新知