E - Unimodal Array CodeForces - 831A
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).
Example
6
1 5 5 5 4 2
YES
5
10 20 30 20 10
YES
4
1 2 1 2
NO
7
3 3 3 3 3 3 3
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).
题解:这是一道判断一组数是是不是单峰的问题,且满足左边严格增加,中间平,最后严格减。
代码为:
#include<iostream>
#include<cstdio>
using namespace std;
#define MAXN 110
int a[MAXN];
int main()
{
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++)
cin>>a[i];
int p=2;
while(a[p]>a[p-1]) p++;
while(a[p]==a[p-1]) p++;
while(a[p]<a[p-1]) p++;
if(p<=n)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}
E - Unimodal Array CodeForces - 831A的更多相关文章
- CodeForces - 831A Unimodal Array 模拟
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces831A Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Code froces 831 A. Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Greg and Array CodeForces 296C 差分数组
Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...
- 【Codeforces Round #424 (Div. 2) A】Unimodal Array
[Link]:http://codeforces.com/contest/831/problem/A [Description] 让你判断一个数列是不是这样一个数列: 一开始是严格上升 然后开始全都是 ...
- Imbalanced Array CodeForces - 817D (思维+单调栈)
You are given an array a consisting of n elements. The imbalance value of some subsegment of this ar ...
- Petya and Array CodeForces - 1042D (树状数组)
D. Petya and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- AC日记——Little Elephant and Array codeforces 221d
221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include ...
- Curious Array Codeforces - 407C(高阶差分(?)) || sequence
https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...
随机推荐
- 如何查看当前linux服务器是否支持虚拟化
[root@localhost ~]# grep -E '(svm|vmx)' /proc/cpuinfo 或者: [root@localhost ~]# cat /proc/cpuinfo 找到fl ...
- ASP.NET Core 1.0: Using Entity Framework Core
伴随着ASP.NET Core 1.0发布的还有Entity Framework Core 1.0; 官方文档链接:https://docs.efproject.net/en/latest/platf ...
- 有关html的标签以及css属性(border、div)
border 边框css属性 边框颜色 border-color边框样式 border-style:solid (实线)dashed(虚线)默认为none边框粗细 border-width:1px:默 ...
- mysql 导出 导入
一.导出 windows下 切换到mysql安装目录bin目录下 导出 数据库lz_garden 下的 所有表结构 到d盘并命名为lz_garden.sql: D:\dev\MySQL\MySQL S ...
- Install Elastic stack
1. 安装环境 系统版本:centos 6.9 java版本:1.8.0_181 程序版本:6.6 (整个stack需保持相同的版本) 2. 安装顺序 1 Elasticsearch 2 Kibana ...
- SpringBoot 源码解析 (十)----- Spring Boot的核心能力 - 集成AOP
本篇主要集成Sping一个重要功能AOP 我们还是先回顾一下以前Spring中是如何使用AOP的,大家可以看看我这篇文章spring5 源码深度解析----- AOP的使用及AOP自定义标签 Spri ...
- ArcGIS 切片与矢量图图层顺序问题
在项目中有个需求:根据图层索引添加图层 看到这个需求一下子想到 map.addLayer(layer,index?) 接口 但是问题出现了,我切片图加载顺序在矢量图之后就不行! map = new M ...
- 线程中synchronized关键字和lock接口的异同
一.synchronized关键字 1.可以用来修饰代码块 synchronized (this) { // 同步的关键字 this 表示当前线程对象 if (num == 0) { break; } ...
- 组长组——“多彩夕阳”APP评价
基于NABCD评论,及改进建议 一.组长组NABCD: N-需求背景: (1)我国老龄化日益加重,已突破两亿.目前人数还在增加,解决老年福祉成为社会关注的民生话题. (2)智能手机越来越普遍,老年人已 ...
- web 开发常用字符串表达式匹配
记录一下 web 开发中常用的一些字符串模式,这是我遇到的一些,后面如果还有的话,欢迎大神提出,会继续更新. 正则表达式 这个主要用在前端的验证,nginx 路径匹配,shell 脚本文本处理,后端感 ...