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 ...
随机推荐
- Java基础-5运算符
一).算数运算符: 算术运算符的功能是做各种算术运算,其操作数可以是字符型.整型或浮点型数据. 运算符 运算 示例 结果 备注 + 加 5+5 10 - 减 4-2 2 * 乘 2*3 6 既 ...
- springboot配多数据源
多数据源配置 https://blog.csdn.net/neosmith/article/details/61202084 https://www.cnblogs.com/zhangboyu/p/7 ...
- PHP excel 设置参数
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1); <?php error_ ...
- 孤荷凌寒自学python第七天 列表的复制与序列的基本运算
孤荷凌寒自学python第七天 列表的复制与序列的基本运算 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) (同步语音:https://www.ximalaya.com/keji/191030 ...
- 1004 Counting Leaves (30 分)(树的遍历)
给出一棵树,问每一层各有多少叶子节点 dfs遍历树 #include<bits/stdc++.h> using namespace std; vector<]; int n,m; i ...
- 常见数据结构图文详解-C++版
目录 简介 一.数组 1. 静态数组 array 2. 动态数组 2.1. vector 2.2. priority_queue 2.3. deque 2.4. stack 2.5. queue二.单 ...
- 选择MariaDB的压缩数据引擎TokuDB
业务运用场景 数据基本不用update, 不频繁的范围查询 数据存储量较大(为以后准备) 选择占用磁盘较小的db 业务对数据库插入操作频繁,为避免影响其它业务,需要将直播业务的DB 独立出来,选择另外 ...
- URAL 1944 大水题模拟
D - Record of the Attack at the Orbit Time Limit:1000MS Memory Limit:65536KB 64bit IO Format ...
- UVALive4374 Drive through MegaCity
题目戳这里. 首先我们对坐标进行离散化,有用的点就变成了\(O(N)\)个.我们假设\(A\)点\(B\)的右边(从\(A\)往\(B\)跑和从\(B\)往\(A\)跑等价),然后我们很容易发现不会往 ...
- libcurl网络连接使用tcp/ip
CURL *curl; CURLcode res; const char *request = "GETas.xxxxE测试发送"; curl_socket_t sockfd; / ...