Codeforces831A Unimodal Array
来源:互联网 发布:北京旅游酒店推荐知乎 编辑:程序博客网 时间:2024/06/04 14:15
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).
61 5 5 5 4 2
YES
510 20 30 20 10
YES
41 2 1 2
NO
73 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 longconst int INF = 0x3f3f3f3f;#define MAXN 2000010int 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
- CF831A-Unimodal Array
- cf424div2 A. Unimodal Array
- A. Unimodal Array
- CodeForces 831A Unimodal Array
- cf round424 A.Unimodal Array
- Codeforces 831 A Unimodal Array
- CodeForces 831A-Unimodal Array
- codeforces 831A Unimodal Array
- A. Unimodal Array(段增减性
- CodeFroces 831A. Unimodal Array(构造题)
- Codeforces #831A: Unimodal Array 题解
- CodeForces 831A:Unimodal Array(模拟)
- Codeforces Round #424 (Div. 2) A. Unimodal Array(水题)
- Codeforces Round #424 (Div. 2) A. Unimodal Array
- Codeforces Round #424 (Div. 2) A. Unimodal Array
- Codeforces Round #424 (Div. 2) A. Unimodal Array
- Codeforces Round #424 (Div. 2) A. Unimodal Array
- iOS 视觉差
- redis五种基本数据类型
- CMPP3.0实现物联网卡发短信遇到的问题
- 读取csv文件到数据库
- mybatis基础
- Codeforces831A Unimodal Array
- JavaScript中Array对象
- 【jzoj5222】【GDOI2018模拟7.12】【A】【数据结构】
- BigDecimal 除法运算出现 java.lang.ArithmeticException
- HDU 1166 敌兵布阵(线段树)(第一部分 单点更新)
- 移动开发----Android开发者网址导航
- FFMPEG学习【libavutil】:Mathematics
- eclipse中Tomcat 引用java类型的动态WEB项目
- Android 视频回放时间轴,支持缩放,拖动,自动移动到最近视频开始时间