题干

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 a 1, a 2, …, a n (1 ≤ a i ≤ 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).

题解

题目中要求的是一个左边单调增,中间恒定,右边单调减的数列,其中三种情况都可以缺失。
因此可以给每种情况附一个值。
单调增为 1,
恒定为 2,
单调减为 3,
由题意得,右边的值不能比左边的值低
特殊情况:n=1时一定成立。

参考代码

#include<bits/stdc++.h>
using namespace std;
int n,a[101],f[101];
int main()
{cin>>n;if(n==1){cout<<"YES";return 0;}for(int i=1;i<=n;i++) cin>>a[i];for(int i=2;i<=n;i++){if(a[i-1]<a[i]) f[i]=1;if(a[i-1]==a[i])f[i]=2;if(a[i-1]>a[i])    f[i]=3;if(f[i]<f[i-1]){cout<<"NO";return 0;}}cout<<"YES";
}

A-Unimodal Array相关推荐

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    昨晚的没来得及打,最近错过好几场CF了,这场应该不算太难 A. Unimodal Array time limit per test 1 second memory limit per test 25 ...

  2. Codeforces Round #424 (Div. 2)

    D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iost ...

  3. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  4. 老男孩上海校区Python面试题

    python面试题 第一章:python基础 数据类型: 1 字典: 1.1 现有字典 dict={'a':24,'g':52,'i':12,'k':33}请按字典中的 value 值进行排序? 1. ...

  5. CF831A-Unimodal Array(单峰阵列)

    A.单峰阵列 Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it ...

  6. php recordarray,Array 数组 - [ php中文手册 ] - 在线原生手册 - php中文网

    用户评论: [#1] florenxe [2015-10-07 18:53:45] //a nice little way to print leap years using array for ($ ...

  7. NumPy — 创建全零、全1、空、arange 数组,array 对象类型,astype 转换数据类型,数组和标量以及数组之间的运算,NumPy 数组共享内存

    NumPy 简介 一个用 python 实现的科学计算包.包括: 1.一个强大的 N 维数组对象 Array : 2.比较成熟的(广播)函数库: 3.用于整合 C/C++ 和 Fortran 代码的工 ...

  8. array.array python yhzf

    关于array: Python 本身没有数组这个说法, 有的就是list和tuple, list就具有其他语言中的数组特性. 至于list和tuple的区别,在于list可以在运行时修改内容和大小,t ...

  9. [JS]请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组。

    请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组. 刚开始复习js题还不太习惯 CSDN上看了一个帖子,说是牛客上的标答, ...

  10. hnswlib RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is to sma

    1. 问题现象 index = hnswlib.Index(space = '100', dim = 512) index.init_index(max_elements = 100, ef_cons ...

最新文章

  1. 修改所有列_宝塔面板安装完的一些列操作
  2. AOP开发——在不修改源代码的前提下,对类里面的方法进行增强 : 前置 后置 环绕 异常||如何得到目标方法的参数和返回值
  3. java web中中文乱码问题汇总
  4. SSM中通过Json做前后端分离
  5. 【转】iOS开发6:UIActionSheet与UIAlertView
  6. 对Java的URL类支持的协议进行扩展的方法
  7. 批处理 java环境_java环境配置简单批处理方法一键OK
  8. 如何在golang代码里面解析容器镜像
  9. 学习Scala: 初学者应该了解的知识
  10. HDFS Archival Storage
  11. 对话夏琳·查布利斯:Primer.AI机器学习工程师是怎样炼成的?
  12. 数据库中间件DBLE学习(一) 基本介绍和快速搭建
  13. F003-牛奶为什么要倒河里 #F1350
  14. Android系统触摸屏移植后出现小圆圈
  15. 丛林木马(数学 思维
  16. 全面认识二极管,一篇文章就够了
  17. 配置FT2232波特率
  18. 糗事百科网站服务器,糗事百科神仙道官网
  19. Elliptic curve cryptography
  20. 老电脑如何安装windows11最新版

热门文章

  1. c语言char10是什么意思,c语言char是什么意思
  2. 设计模式 策略模式(Strategy)介绍和使用
  3. SpringBoot Web开发
  4. DASCTF X CBCTF 2022九月挑战赛 dino3d
  5. Android开发者指南-Manifest.xml-uses-feature
  6. Python—网络编程_Mail
  7. 《人性的弱点》简明总结
  8. MACD底背离选股公式——通达信、同花顺
  9. 3D结构光能否决定未来行业发展新方向?
  10. Connection reset by 20.205.243.166 port 22fatal: Could not read from remote repository.Please mak