CSU - 2062 Z‘s Array
2024-08-29 01:58:48
Description
Z likes to play with array. One day his teacher gave him an array of n elements, and ask Z whether the array is a "m-peek" array.
A "m-peek" array is an array which has exactly m peek.
a term a[i] is called a peek if and only if a[i]>a[i − 1] and a[i]>a[i + 1]
If the array has exactly m peeks, the array is called a "m-peek" array.
Input
The first line is the case number T
each case has two integer n, m where n denotes the number of elements in the array
then followed by n 32-bit signed integers in the array.
1 ≤ T ≤ 100
1 ≤ n ≤ 1000000
0 ≤ m ≤ n
Output
For each case,
print a single word "Yes" without quotation when the array is a "m-peek" array.
print "No" without quotation otherwise.
Sample Input
2
5 1
5 7 11 2 1
4 1
4 5 5 6
Sample Output
Yes
No
Hint
Source
Author
周杰辉
#include<stdio.h>
#define MAXN 1000010
int a[MAXN];
int main()
{
int t, n, m;
while (~scanf("%d", &t))
{
while (t--)
{
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
int num = 0;
for (int i = 1; i < n-1; i++)
{
if (a[i] >a[i - 1] && a[i] > a[i + 1])
{
num++;
}
}
if (num == m)
printf("Yes\n");
else
printf("No\n");
}
}
}
最新文章
- Google数据交换格式:ProtoBuf
- browser-sync
- 《Linux内核设计与实现》 Chapter4 读书笔记
- js常见数字处理整理
- python UTC,时间戳,字符串转换
- 400 bad request
- [LeetCode]题解(python):141-Linked List Cycle
- myeclipse 调试JSP页面
- OC类的介绍
- 浅谈MVC Form认证
- 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- 创建一个离线优先,数据驱动的渐进式 Web 应用程序
- POJ 1873 The Fortified Forest [凸包 枚举]
- 【转】网页禁止后退键BackSpace的JavaScript实现(兼容IE、Chrome、Firefox、Opera)
- JGUI源码:右键菜单实现(12)
- 搭建私有CA服务器
- python WebDriver如何处理右键菜单
- unity 之 no cameras rendering
- PYQT5学习笔记之各模块介绍
- 全局设置axios发送cookie(axios 默认不发送cookie)
热门文章
- shell学习1---基本的shell命令
- 好的MongoDB学习文章链接
- [整理]C中的静态存储区
- Java后台获取前端utf-8格式&;nbsp;空格,使用trim()消除不了的解决办法
- 20155234 2016-2017-2 《Java程序设计》第5周学习总结
- 微服务深入浅出(6)-- 熔断器Hystrix
- HDU 1256 画8 模拟题
- Python练习-短小精干版三级";片儿";
- 数位DP入门(A - 不要62 HDU - 2089 &;&;B - Bomb HDU - 3555 )
- 利用python编写不同环境下都能运行的测试脚本