zoukankan      html  css  js  c++  java
  • 人生第一道cf的题

    题目链接
     http://codeforces.com/contest/831/problem/A
    A. Unimodal Array
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Array of integers is unimodal, if:

    • it is strictly increasing in the beginning;
    • after that it is constant;
    • after that it is strictly decreasing.

    The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

    For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

    Write a program that checks if an array is unimodal.

    Input

    The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

    Output

    Print "YES" if the given array is unimodal. Otherwise, print "NO".

    You can output each letter in any case (upper or lower).

    Examples
    input
    6
    1 5 5 5 4 2
    output
    YES
    input
    5
    10 20 30 20 10
    output
    YES
    input
    4
    1 2 1 2
    output
    NO
    input
    7
    3 3 3 3 3 3 3
    output
    YES
    Note

    In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

     1 // ab.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdio.h"
     5 #include<iostream>
     6 using namespace std;
     7 bool is_Unimodal (int n)
     8 {
     9     int num_before;
    10     int num;
    11     int flag=1;
    12     num_before=num=0;
    13     for(int i=1; i<=n; i++)
    14     {
    15         scanf("%d",&num);
    16         if(i==1)
    17         {
    18             num_before=num;
    19         }
    20         else
    21         {
    22             if(num_before<num&&flag==1)
    23             {
    24                 num_before=num;
    25 
    26                 continue;
    27 
    28             }
    29 
    30             if(flag==1&&num_before==num)
    31             {
    32                 flag=2;
    33                 num_before=num;
    34 
    35                 continue;
    36             }
    37 
    38 
    39             if(flag==2&&num_before==num)
    40             {
    41                 num_before=num;
    42 
    43                 continue;
    44             }
    45             if(flag==1&&num_before>num)
    46             {
    47                 flag=3;
    48                 num_before=num;
    49 
    50                 continue;
    51             }
    52             if(flag==2&&num_before>num)
    53             {
    54                 flag=3;
    55                 num_before=num;
    56 
    57                 continue;
    58             }
    59             if(flag==3&&num_before>num)
    60             {
    61                 num_before=num;
    62 
    63                 continue;
    64             }
    65             flag=0;
    66         }
    67 
    68     }
    69 
    70     if(flag==0)
    71         return false;
    72     else
    73         return true;
    74 }
    75 int main()
    76 {
    77     int n;
    78     scanf("%d",&n);
    79     cout<<(is_Unimodal (n)?"YES":"NO")<<endl;
    80     return 0;
    81 }
  • 相关阅读:
    Sql与Asp.Net数据类型对应
    EditPlus 使用技巧集萃
    VB.NET and C# Comparison
    测试后行之CodeSmith模板
    ASP.NET需要改进的地方
    LeetCode: Minimum Path Sum
    LeetCode: Merge k Sorted Lists
    LeetCode: Merge Intervals
    LeetCode: Maximum Subarray
    LeetCode: Median of Two Sorted Arrays
  • 原文地址:https://www.cnblogs.com/fairy-wzp/p/7197355.html
Copyright © 2011-2022 走看看