zoukankan      html  css  js  c++  java
  • CSU

    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
    ");
    			else
    				printf("No
    ");
    		}
    	}
    }

  • 相关阅读:
    第13章 子查询和集合运算
    第12章 SQL联接
    第11章 分组函数 ​
    第10章 单行函数 ​
    第15章 RMAN备份 ​
    第1章
    OCP/OCA Oracle 学习001
    Linq之Sum用法新体会
    java中的异常
    android SQLite使用SQLiteOpenHelper类对数据库进行操作
  • 原文地址:https://www.cnblogs.com/csu-lmw/p/9124457.html
Copyright © 2011-2022 走看看