CF-831A
A. Unimodal Arraytime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputPrint "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examplesinput6
1 5 5 5 4 2outputYESinput5
10 20 30 20 10outputYESinput4
1 2 1 2outputNOinput7
3 3 3 3 3 3 3outputYESNoteIn 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).
题意:
递增,相等,递减只能按顺序出现,否则为“NO”。
AC代码:
#include<bits/stdc++.h>
using namespace std; int cmp(int x,int y){
if(x<y)
return ;
if(x==y)
return ;
if(x>y)
return ;
} int main(){
int n,x[];
cin>>n;
int t=;
for(int i=;i<n;i++){
cin>>x[i];
}
for(int i=;i<n;i++){
if(cmp(x[i-],x[i])<t){
cout<<"NO"<<endl;
return ;
}
else{
t=cmp(x[i-],x[i]);
}
}
cout<<"YES"<<endl;
return ;
}
CF-831A的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
随机推荐
- JavaScript语言基础9
我们先看看以下这段代码: <span style="font-size:18px;"><HTML> <HEAD> <TITLE>He ...
- 编程算法 - 多重部分和问题 代码(C)
多重部分和问题 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n种不同大小的数字a, 每种各m个. 推断能否够从这些数字之中选出若干使它们的 ...
- JS 省市两级联动(不带地区版本)
基于网上找的一个版本改造,因为项目需求不需要地区只要省.市,所以做了改版,两个input上直接取出了数据 <html> <head> <script src=" ...
- 区分拖曳(drag)和点击(click)事件
假设页面上有一个a标签: <a href="http://www.google.com">google</a> 现在需要对这个标签进行拖放操作,会发现当拖曳 ...
- 根据百度地图API获取指定地点的经纬度
做项目时,遇到对地点获取地图中对应的经纬度,作一下笔记,以备以后直接使用 package com.hpzx.data; import java.io.BufferedReader; import ja ...
- 九度OJ 1128:求平均年龄 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2080 解决:1084 题目描述: 班上有学生若干名,给出每名学生的年龄(整数),求班上所有学生的平均年龄,保留到小数点后两位. 输入: 第 ...
- android——array中设置选项
Android中,R.array是提取XML资源文件中String数组的方法.具体定义和提取的方法如下: 1)在R.array中定义字符数组 <?xml version="1.0&qu ...
- Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴
题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...
- Codeforces Round #398 (Div. 2) C. Garland —— DFS
题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做 ...
- 关于ArcGIS动态图层空间内栅格数据,JS前端显示颜色不正确的解决方案
ArcGIS的动态空间,可承载Table,Shp,Raster等数据. 我们的需求是,每天客户有新的卫星数据,但是不同类型,有多波段Landsat卫星数据,有Modis数据等.不定期更新到共享文件夹, ...