Peak
A sequence of \(n\) integers \(a_1, a_2, \dots, a_n\) is called a peak, if and only if there exists exactly one integer \(k\) such that \(1 < k < n\), and \(a_i < a_{i+1}\) for all \(1 \le i < k\), and \(a_{i-1} > a_i\) for all \(k < i \le n\).
Given an integer sequence, please tell us if it's a peak or not.
Input
There are multiple test cases. The first line of the input contains an integer \(T\), indicating the number of test cases. For each test case:
The first line contains an integer \(n\) (\(3 \le n \le 10^5\)), indicating the length of the sequence.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (\(1 \le a_i \le 2 \times 10^9\)), indicating the integer sequence.
It's guaranteed that the sum of \(n\) in all test cases won't exceed \(10^6\).
Output
For each test case output one line. If the given integer sequence is a peak, output "Yes" (without quotes), otherwise output "No" (without quotes).
Sample Input
7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2
Sample Output
Yes
No
No
No
Yes
No
No
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{
int t;;
cin>>t;
while(t--){
int f=1;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
int pos=-1;
for(int i=0;i<n;i++){
if(i!=0&&i!=n-1){
if(a[i-1]<a[i] && a[i]>a[i+1]){
pos=i;
}
}
}
//cout<<pos<<" "<<a[pos]<<endl;
for(int i=0;i<n;i++){
if(i<pos){
if(a[i]>=a[i+1]) f=0;
}
if(i>pos){
if(a[i]>=a[i-1]) f=0;
}
}
f?puts("Yes"):puts("No");
}
}
Peak的更多相关文章
- [LeetCode] Find Peak Element 求数组的局部峰值
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- LeetCode 162 Find Peak Element
Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...
- Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- [LintCode] Find Peak Element 求数组的峰值
There is an integer array which has the following features: The numbers in adjacent positions are di ...
- lintcode 75 Find Peak Element
Hi 大家,这道题是lintcode上的find peak element的题,不是leecode的那道, 这两道题是有区别的,这道题的题目中说明了:只有左右两侧的数都小于某个元素,这种才是峰值, 而 ...
- 【leetcode】Find Peak Element
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- ChIP-seq Peak caller MACS index out of range问题解决
使用MACS1.4 进行peak calling的时候发现一个比较奇怪的问题: 我的某些文件无法被MACS1.4 进行peak calling,出现如下的信息: Traceback (most rec ...
- find the peak value
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- Java for LeetCode 162 Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- LeetCode Find Peak Element
原题链接在这里:https://leetcode.com/problems/find-peak-element/ 题目: A peak element is an element that is gr ...
随机推荐
- day06_04 购物车讲解02
1.0 补充知识 a,b = [2,3] print(a) print(b) #>>>2 #>>>3 a,b = (2,3) print(a) print(b) # ...
- 利用jsoup抓取网页图片
jsoup简介 jsoup is a Java library for working with real-world HTML. It provides a very convenient API ...
- codeblocks17.12 debug 报错:ERROR: You need to specify a debugger program in the debuggers's settings.
DebugERROR: You need to specify a debugger program in the debuggers's settings.(For MinGW compilers, ...
- 容器基础(一): Docker介绍
IaaS IaaS阶段, 用户租借基础设施,但是还是需要像以前管理服务器那样,用脚本或者手工方式在这些机器上部署应用.这个过程中当然难免会碰到云端机器和本地机器环境不一致的问题.想想每一次同步不同机器 ...
- JSP/Servlet Web 学习笔记 DayThree
JSP内置对象 使用JSP语法可以存取这些内置对象来执行JSP网页的Servlet环境相互作用.内置对象其实是由特定的Java类所产生的.每一种内置对象都映射到一个特定的Java类或者端口,在服务器运 ...
- 如何使能diskquota
quotacheck -avug quotaon -avug setquota -u test1 10000 20000 /mountpoint quota -uv test1
- JZOJ 5305 C先生
题意: 有一个n个点,m条边的图,没有重边.自环,且每一条边最多属于一个环路. 给出q组询问,每次询问u,v两点间的路径有多少种可能. 思路: 先看下方样例说明: 由样例说明可以得知,路径上每经过一个 ...
- [poj] 3180 the cow prom
原题 这是一道强连通分量板子题. 我们只用输出点数大于1的强连通分量的个数! #include<cstdio> #include<algorithm> #include< ...
- 3.Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件
先说和虚拟化技术的区别 难道虚拟技术就做不到吗? 不不不,虚拟技术也可以做到,但是会有一定程度的性能损失,灵活度也会下降.容器技术不是模仿硬件层次,而是 在Linux内核里使用cgroup和names ...
- codeforces gym/100814 humming distance (二进制位数比较)
Gym - 100814I I. Salem time limit per test 1 second memory limit per test 1024 megabytes input stand ...