Codeforces #831A: Unimodal Array 题解

本文介绍了一种简单有效的算法,用于判断给定数列的趋势变化,包括上升、平台及随后的下降阶段。通过扫描数列并标记关键转折点,该算法能够快速确定数列是否符合特定的升-平-降模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这题很容易写错

先从左往右扫,找到不再上升的点

然后跳过中间的那些平着的点

最后看剩下的是否下降

要注意的是,下降部分的第一个要小于平台

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <bitset>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int zero_stand=1500;
const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
int a[101];

int main ()
{
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	if (n==1 || n==2)
	{
		printf("YES\n");
		return 0;
	}
	int pos=1;
	while (pos<=n-1 && a[pos]<a[pos+1]) pos++;
	while (pos<=n-1 && a[pos]==a[pos+1]) pos++;
	for (i=pos;i<=n-1;i++) if (a[i]<=a[i+1])
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值