Codeforces831A 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
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>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
#define MAXN 2000010 int a[100005];
int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
int flag=0;
int fl=0;
for(int i=1; i<n; i++)
{
if(flag==0)
{
if(a[i]>a[i-1])
continue;
else if(a[i]==a[i-1])
flag=1;
else if(a[i]<a[i-1])
flag=2;
}
else if(flag==1)
{
if(a[i]>a[i-1])
{
fl=1;
break;
}
else if(a[i]==a[i-1])
continue;
else if(a[i]<a[i-1])
flag=2;
}
else if(flag==2)
{
if(a[i]>=a[i-1])
{
fl=1;
break;
}
}
}
printf("%s\n",fl?"NO":"YES");
return 0;
}
Codeforces831A Unimodal Array的更多相关文章
- CodeForces - 831A 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 ...
- 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) A】Unimodal Array
[Link]:http://codeforces.com/contest/831/problem/A [Description] 让你判断一个数列是不是这样一个数列: 一开始是严格上升 然后开始全都是 ...
- 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, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF-831A
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
随机推荐
- Python学习—数据库篇之SQL补充
一.SQL注入问题 在使用pymysql进行信息查询时,推荐使用传参的方式,禁止使用字符串拼接方式,因为字符串拼接往往会带来sql注入的问题 # -*- coding:utf-8 -*- # auth ...
- Python设计模式 - UML - 定时图(Timing Diagram)
简介 定时图也是一种交互图,用来描述对象或实体随时间变化的状态或值,及其相应的时间或期限约束.定时图应用较广,并不局限于软件工程领域. 定时图侧重与时间线相关的值或状态的改变,这些改变可能来自于收到消 ...
- Hillstone基础上网配置
1.接口配置 1)进入设备管理界面后,点击左边 网络—接口: 2)选择相应的接口,点击编辑: 3)在接口配置界面中,选择接口的安全域类型(三层接口即为三层安全域,二层接口即为二层安全域).安全域名称 ...
- easyui 单元格超出鼠标放上弹出全部
其他方式:https://www.cnblogs.com/raitorei/p/9878192.html onLoadSuccess : function(data) { //单元格超出部分隐藏并鼠标 ...
- 分布式事务Hmily TCC源码--学习整合
一.什么是分布式事务 分布式事务是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点上, 本质上来说,分布式事务是为了保证不同数据库的数据一致性 TCC事务主 ...
- python中的继承和多态
继承 继承的表现方式: class Animal(): pass class Cat(Animal): #animal是cat的父类,也可以说是基类 pass print(Cat.__bases__) ...
- 创建服务的注册与发现 Eureka (四)
一.eureka注册中心 1.创建一个工程 工程名:microservicecloud-eureka-7001 2.向pom文件中增加如下: <dependencies> <!--e ...
- UI行业发展预测 & 系列规划的调整
又双叒叕拖更了,上一篇还是1月22号更新的,这都3月9号了…… 前面几期把职业规划.能力分析.几个分析用的设计理论都写完了,当然实际工作中用到的方法论不止上面这些,后续会接着学习: 如果你的目标是一线 ...
- php实现下载模板与上传模板解析
<? //下载模板的请求 if(isset($_GET['action']) && $_GET['action'] =='down_group_excel'){ $code = ...
- net::ERR_CONNECTION_RESET 问题排查
后台服务器代码有问题 实体不对称,导致映射不对