您的位置:首页 > 其它

Codeforces #831A: Unimodal Array 题解

2017-07-14 21:52 447 查看
这题很容易写错

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

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

最后看剩下的是否下降

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: