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;
}
先从左往右扫,找到不再上升的点
然后跳过中间的那些平着的点
最后看剩下的是否下降
要注意的是,下降部分的第一个要小于平台
#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;
}
相关文章推荐
- 【LeetCode题解】数组Array
- leetcode题解-410. Split Array Largest Sum
- leetcode 题解 || Remove Duplicates from Sorted Array 问题
- A. Unimodal Array(段增减性
- leetcode题解:Search in Rotated Sorted Array(旋转排序数组查找)
- leetcode题解-26. Remove Duplicates from Sorted Array && 27. Remove Element
- leetcode题解Java | 421. Maximum XOR of Two Numbers in an Array
- 【题解】【数组】【查找】【Leetcode】Search in Rotated Sorted Array
- [LeetCode]题解(python):108-Convert Sorted Array to Binary Search Tree
- 1/21集训二 模拟+贪心 E.(模拟 判断一组序列是否满足先增再平后减)Unimodal Array
- A. Unimodal Array(段增减性
- leetcode 题解:Search in Rotated Sorted Array II (旋转已排序数组查找2)
- LeetCode题解:Rotate Array
- LeetCode题解系列--215. Kth Largest Element in an Array
- LeetCode题解:Remove Duplicates from Sorted Array I and II
- CodeForces 831A Unimodal Array
- A. Unimodal Array(段增减性
- [LeetCode]题解(python):153-Find Minimum in Rotated Sorted Array
- leetcode 540. Single Element in a Sorted Array 题解
- [LeetCode]题解(python):026-Remove Duplicates from Sorted Array