• ZOJ


    A sequence of integers is called a peak, if and only if there exists exactly one integer such that , and for all , and for all .

    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 , indicating the number of test cases. For each test case:

    The first line contains an integer (), indicating the length of the sequence.

    The second line contains integers (), 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
    思路:这道题挺骚的,一开始我直接判断峰值有没有出现,出现的话就标记一下,再继续寻找,并且判断相不相等的情况,结果WA了很多次,是我想太多了(都怪我菜)。然后就用判断(最左边的峰值)是否与(最右边的峰值)相等的思路。
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <string>
    #include <cstring>
    using namespace std;
    #define ll long long
    const int inf = 0xffffff;
    const int maxn = 1e6;
    int t, n;
    ll a[maxn];
    int main()
    {
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d", &n);
            int flag = 0;
            int l = 0, r = n-1;
            for(int i = 0; i<n; i++)
            {
                scanf("%lld", &a[i]);
            }
            for(int i = 0; i<n-1; i++)
            {
                if(a[i]>a[i+1])
                {
                    l = i;
    //                cout<<l<<endl;
                    break;
                }
                else if(a[i] == a[i+1])
                {
                    flag = 1;
                }
            }
            for(int i = n-1; i>0; i--)
            {
                if(a[i-1]<a[i])
                {
                    r = i;
    //                cout<<r<<endl;
                    break;
                }
                else if(a[i-1] == a[i])
                {
                    flag = 1;
                }
            }
            if(l == r && l>0 && l<n-1 && flag == 0)printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }


  • 相关阅读:
    remove white space from read
    optimize the access speed of django website
    dowload image from requests
    run jupyter from command
    crawl wechat page
    python version 2.7 required which was not found in the registry windows 7
    health
    alternate rows shading using conditional formatting
    word
    【JAVA基础】static 关键字
  • 原文地址:https://www.cnblogs.com/RootVount/p/10667540.html
Copyright © 2020-2023  润新知