Code froces 831 A. Unimodal Array
1 second
256 megabytes
standard input
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.
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.
Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
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
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
int a[],n,x;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int l=,r=n;
while(l<n && a[l]<a[l+]) l++;
while(r> && a[r]<a[r-]) r--;
for(int i=l+;i<=r;i++)
if(a[i]!=a[l]) return puts("NO"),;
puts("YES");
return ;
}
Code froces 831 A. Unimodal Array的更多相关文章
- Codeforces831A Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces - 831A Unimodal Array 模拟
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 【Codeforces Round #424 (Div. 2) A】Unimodal Array
[Link]:http://codeforces.com/contest/831/problem/A [Description] 让你判断一个数列是不是这样一个数列: 一开始是严格上升 然后开始全都是 ...
- E - Unimodal Array CodeForces - 831A
Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- C++ std::array
std::array template < class T, size_t N > class array; Code Example #include <iostream> ...
- Array.prototype.slice.call(document.querySelectorAll('a'), 0)
Array.prototype.slice.call(document.querySelectorAll('a'), 0)的作用就是将一个DOM NodeList 转换成一个数组. slice()方法 ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 3
1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 2
1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...
随机推荐
- css3 实现加载滚动条效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Alternating Sum
http://codeforces.com/problemset/problem/963/A 不考虑正负的话,每两项之间之间公比为b/a,考虑正负,则把k段作为循环节,循环节育循环节之间公比为(b/a ...
- codefroces 873 B. Balanced Substring && X73(前缀和思想)
B. Balanced Substring You are given a string s consisting only of characters 0 and 1. A substring [l ...
- 实现人脸识别性别之路---matplotlib之注释
一.准备数据 利用np.linspace()函数得到一定范围内的数据集 利用2*x+1的公式求出y 二.创建窗口 三.根据具有规律的数据画图 四.调整坐标轴 1.将原本的坐标轴的上轴和右轴去掉,使用基 ...
- 彻底分析虚拟视频驱动vivi(三)
在Ubuntu系统中接上usb摄像头设备时,系统会自动安装对应的usb设备驱动程序.我们现在要使用自己编译的vivi驱动,该怎么办呢? 1.先安装系统自带的vivi驱动和它所依赖的所有驱动:sudo ...
- 无闻go编程基础笔记
Go语言做Web编程非常方便,并且在开发效率和程序运行效率方面都非常优秀.相比于Java,其最大的优势就是简便易用,而相比于PHP,它最大的优势就是性能好. (go做web)推荐Gorilla的库,里 ...
- jQuery判断字符串是否含有中文字符
//判断字符串是不是中文String.prototype.isChinese = function () { var reg = /[^\x00-\xff]/ig;//判断是否存在中文和全角字符 ...
- PHP的数组分为两种类型,一种是索引数组,一种是关联数组。有如下关联数组,我们如何获取它的第一个key和value呢?
示例:$items=array('name'=>'sjm','age'=>'26','sex' => '男','location'=>'北京'); //当然用循环然后break ...
- Linux学习总结(2)——linux常用命令大全
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
- Node.js转化GBK编码 - iconv-lite
node当使用node获取GBK编码的数据时,nodejs仅仅支持utf-8,node没有提供转换编码的原生支持,有倒是有一个模块iconv能干这个事,但须要本地方法,VC++库的支持.国外有个大牛写 ...