zoukankan      html  css  js  c++  java
  • HDU 波峰

    Problem @

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
    Total Submission(s) : 100   Accepted Submission(s) : 41
    Problem Description
    A sequence of $n$ integers $a_1, a_2, dots, a_n$ is called a peak, if and only if there exists exactly one integer $k$ such that $1 < k < n$, and $a_i < a_{i+1}$ for all $1 le i < k$, and $a_{i-1} > a_i$ for all $k < i le 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 le n le 10^5$), indicating the length of the sequence.

    The second line contains $n$ integers $a_1, a_2, dots, a_n$ ($1 le a_i le 2 imes 10^9$), indicating the integer sequence.

    It's guaranteed that the sum of $n$ in all test cases won't exceed $10^6$.

    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

    求给定数列是不是波峰,只能是左边递增右边递减
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <cstdio>
    
    using namespace std ; 
    
    #define maxn 1100000
    int num[maxn] ; 
    
    int t , n ; 
    
    int main(){
        cin >> t ; 
        while(t--){
            cin >> n ; 
            for(int i=1 ; i<=n ; i++){
                cin >> num[i] ; 
            }
            int sum1 = 0  ; 
            int pos = -1 ; 
            for(int i=2 ; i<n ; i++){
                if(num[i-1] < num[i] && num[i] > num[i+1]){
                    sum1 ++ ; 
                    pos = i ; 
                }
    
            }
            bool flag = true ; 
            for(int i=1 ; i<pos ; i++){
                if(num[i] >= num[i+1]){
                    flag = false ; 
                    break ; 
                }
            }
            for(int i=pos ; i<n ; i++){
                if(flag == false) break ; 
                if(num[i+1]>=num[i]){
                    flag = false ;
                    break ;  
                }
            }
            if(flag) cout << "Yes" << endl ; 
            else cout << "No" << endl ; 
        }
    }
  • 相关阅读:
    奢想下财务自由吧--理想生活啊
    [翻译] AGG 之贝塞尔插值
    Beginning Silverlight 4 in C#Welcome to Silverlight 4[学习笔记]
    从属性赋值到MVVM模式详解
    Beginning Silverlight 4 in C#Silverlight的布局管理学习笔记
    Beginning Silverlight 4 in C#Silverlight工具包
    不用IDE写C#的Hello World
    NHibernate使用无状态Sessions
    Beginning Silverlight 4 in C#Silverlight控件
    NHibernate使用session.Merge[翻译]
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9064853.html
Copyright © 2011-2022 走看看