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 ...
随机推荐
- 如何使用malloc申请一个二位数组
fscanf(file, "%d", &iVertexNum); // Read number of Vertices double **G = (double **)ma ...
- oracle数据库DB_NAME、DBID、DB_UNIQUE_NAME等的区别
目录 DB_NAME DBID DB_UNIQUE_NAME: INSTANCE_NAME: SID: SERVICE_NAME GLOBAL_DATABASE_NAME: DB_NAME ①是数据库 ...
- USACO Section1.3 Combination Lock 解题报告
combo解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- JMeter学习笔记(九) 参数化2--CSV Data Set Config
2.CSV Data Set Config 1)添加 CSV Data Set Confi 2)配置CSV Data Set Config 3)添加HTTP请求,引用参数,格式 ${} 4)执行HTT ...
- Cannot create a secure XMLInputFactory --CXF调用出错
在调用方法前加上下面三句即可调用成功: Properties props = System.getProperties(); props.setProperty("org.apache.cx ...
- 稀疏矩阵相乘-Python版
稀疏矩阵相乘-Python版 Given two sparse matrices A and B, return the r ...
- 第二节 PHPUnit测试的剖析
现在,让我们仔细看看测试结构的样子. 让我们从一个简单的测试用例开始,它将显示基本的PHPUnit测试结构. 以下代码片段是测试用于排序数组的两个PHP函数的一个非常基本的示例:asort()用于对数 ...
- JS正则表达式 简单应用
知识点: 先生成一个正则规则的对象,使用test()对传入的字符串进行验证,返回布尔类型 代码: <!doctype html><html><head> <m ...
- Linux命令 -磁盘和文件系统类
声明:本文所涉及到的Linux命令均为最常见的用法,未列举之参数,自行查阅man 1.df 磁盘容量 -h 以人类易读方式展示(GB.KB)等 df -h /usr 2.du 文件或目录的容量 -s ...
- [LOJ #2162]「POI2011」Garbage
题目大意:给一张$n$个点$m$条边的无向图,每条边是黑色的或白色的,要求变成一个目标颜色.可以从任意一个点开始,走一个简单环,回到开始的点,所经过的边颜色翻转.可以走无数次.问是否有一个方案完成目标 ...