Codeforces
来源:互联网 发布:lol优化电脑提高fps 编辑:程序博客网 时间:2024/06/01 20:35
A. Unimodal Array
题目链接
分类:模拟
1.题意概述
给你n个数,定义它的 unimodal 特征满足:
- 在开头严格单调递增
- 之后维持连续片段
- 之后严格单调递减
并且单增和单减可能不同时出现或者都不出现,连续片段长度也可能为1,现在要你判断这n个数是否具有这样的特征?
2.解题思路
- 特征已经给出了,我们判断无非抓住几个特点:
- 平稳之前可以上升,平稳之后不能上升
- 下降之后不能平稳
- 平稳长度可能为1
3.AC代码
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 100010#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)#define Close() ios::sync_with_stdio(0),cin.tie(0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;int a[111];int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock();#endif int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); bool inc = 0, dec = 0, hod = 0, flag = 1; for (int i = 1; i < n; i++) if (a[i] < a[i + 1]) { if (hod || dec) { flag = 0; break; } else if (!inc) inc = 1; } else if (a[i] == a[i + 1]) { if (dec) { flag = 0; break; } hod = 1; } else if (a[i] > a[i + 1]) dec = 1; if (flag) puts("YES"); else puts("NO");#ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time);#endif return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- spring Quartz 源码分析--触发器类CronTriggerBean源码剖析
- GIT 学习 day03
- WooCommerce——怎么修改“添加到购物车”按钮的文字和链接
- JavaScript实现的可变动态数字键盘控件三种方式
- 高性能网络编程
- Codeforces
- java基础易错题
- 深入理解 Android 之 View 的绘制流程(一)
- Python联系笔记2[列表,元组,集合,字典,函数,文件操作,模块,类]
- Python:序列化二叉树
- KS109的STM32的移植
- Codeforces
- 单点LDAP安装配置
- 使用JVisualVM远程监控Tomcat