CodeForces - 831A 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<stdio.h>
bool flag;
bool flag1;
bool flag2;
int main()
{
int n;
int a[105];
while (~scanf("%d", &n))
{
flag = true;
flag1 = true;
flag2 = true;
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
if (n == 1)
{
printf("YES\n");
continue;
}
for (int i = 1; i < n; i++)
{
if (a[i] == a[i - 1]&&flag1 )
{
flag = false;
}
else if (a[i]<a[i - 1])
{
flag = false;
flag1 = false;
}
else if (a[i] > a[i - 1] && (!flag||!flag1))
{
flag2 = false;
break;
}
else if (a[i] == a[i - 1] &&!flag1)
{
flag2 = false;
}
}
if (!flag2)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}
CodeForces - 831A Unimodal Array 模拟的更多相关文章
- Codeforces 371A K-Periodic Array(模拟)
题目链接 K-Periodic Array 简单题,直接模拟即可. #include <bits/stdc++.h> using namespace std; #define REP(i, ...
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- Codeforces831A Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 1077C Good Array 坑 C
Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- codeforces 407C Curious Array
codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- 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 ...
随机推荐
- 20155330 2016-2017-2 《Java程序设计》第七周学习总结
20155330 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 学习目标 了解Lambda语法 了解方法引用 了解Fucntional与Stream API ...
- flask跨域请求三行代码搞定
flask跨域请求三行代码就可以搞定.但是请注意几点: 第一:只能返回json格式数据,比如list.ndarray等都不可以 第二:返回的对象必须是是字符串.元组.响应实例或WSGI可调用. pyt ...
- Spring Boot1.5X升级到2.0
配置文件 大量的Servlet专属的server.* properties被移到了server.servlet下 拦截器 public class MyWebMvcConfigurerAdapter ...
- 自然语言处理词向量模型-word2vec
自然语言处理与深度学习: 语言模型: N-gram模型: N-Gram模型:在自然语言里有一个模型叫做n-gram,表示文字或语言中的n个连续的单词组成序列.在进行自然语言分析时,使用n-gram或者 ...
- springcloud中eureka集群unavailable-replicas
unavailable-replicas 配置了集群,但是在注册中心显示另外的几个集群地址是不可用的: 1 首先需要再host中添加服务名映射,如果应映射了再看是否在yml中配置了prefer-ip- ...
- python3之pymysql模块
1.python3 MySQL数据库链接模块 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb. PyMySQL 遵循 Pyt ...
- MVVM模式的 数据绑定
数据绑定要达到的效果 数据绑定要达到什么效果呢,就是在界面中绑定了数据源之后,数据在界面上的修改能反映到绑定源,同时绑定源的修改也能反映到界面上.从界面反映到绑定的数据源是很容易理解的,因为在绑定过程 ...
- vs2012 连接oracle11g 及数据的insert及select 的总结
下载链接Oracle 11g所需的驱动ODTwithODAC1120320_32bit,下载链接为http://www.oracle.com/technetwork/topics/dotnet/uti ...
- ASP防XSS代码
原作是在GitHub上,基于Node.js所写.但是..ASP的JS引擎跟V8又有些不同..于是,嗯.. <% Function AntiXSS_VbsTrim(s) AntiXSS_VbsTr ...
- 虚拟机 windows xp sp3 原版
原版的镜像:http://www.7xdown.com/Download.asp?ID=3319&URL=http://d5.7xdown.com/soft2/&file=Window ...