The 15th ZJP ACM - Pro.A Peak

A sequence of integers a 1 , a 2 , , a n is called a peak, if and only if there exists exactly one integer k such that 1 < k < n , and a 1 < a 2 for all , a i 1 > a i and for all k < i n .

Given an integer sequence, please tell us if it’s a peak or not.
Input

There are multiple test cases. The first line of the input contains an integer T , indicating the number of test cases. For each test case:

The first line contains an integer n ( 3 n 10 5 ) , indicating the length of the sequence.

The second line contains integers a 1 , a 2 , , a n ( 1 a i 2 × 10 9 ), indicating the integer sequence.

It’s guaranteed that the sum of in all test cases won’t exceed .

Output

For each test case output one line. If the given integer sequence is a peak, output “Yes” (without quotes), otherwise output “No” (without quotes).

Sample Input

7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2
Sample Output

Yes
No
No
No
Yes
No
No


/*
* Peak
* 在峰值前为单调递增,峰值后单调递减。
*/

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int a[2]={0};  //这玩意这样就差不多了

void print(int f1,int f2)
{
    if(f1&&f2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int isStrictInc = 0,isStrictDec = 0,isOK = 0;

void init()
{
    isStrictInc = 0,isStrictDec = 0,isOK = 0;
}

void initWA()
{
    isStrictInc = 1,isStrictDec = 0,isOK = 0;
}

int getI(int x)
{
    return x%2;
}

int main()
{
    int test,n ;

    cin >> test;
    while (test--) {
        init();
        cin >> n;
        cin >> a[0];
        for (int i = 1; i < n ; ++i) {

            cin >> a[getI(i)];
            if(!isOK){
                if( a[getI(i)] > a[getI(i+1)]) {
                    if( !isStrictInc && !isStrictDec ) isStrictInc = 1;
                    else if( isStrictInc && isStrictDec ) initWA();
                }
                else
                    if(a[getI(i)] == a[getI(i+1)])
                    {
                        initWA();
                        continue;
                    }else{
                        if(isStrictInc ) isStrictDec = 1;
                        else{
                            initWA();
                            continue;
                        }
                    }

            }

        }
        print(isStrictInc, isStrictDec);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_31979619/article/details/80154372
今日推荐