5.20 Vj F – Nastya and Door

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//题意是给你n个数,让你在其中找一串长度为k的数的最左端,使这段k中山峰数最多,并求最多的山峰数
int  main( )
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,r=1,maxx=0,res=0;
        cin>>n>>k;
        int a[n+2],b[n+2];
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            if(i>=2&&a[i-1]>a[i-2]&&a[i-1]>a[i])
            {
                res++;
            }
            b[i]=res;//记录山峰的下标
        }
        //    1 2 4 1 2 4 1 2
        //res 0 0 1 1 1 2 2 2
        for(int i=0; i+k-1<n; i++)
        {
            if(maxx<b[i+k-1]-b[i+1])//找出k段中山峰所在位置
            {
                r=i+1;
            }
            maxx=max(maxx,b[i+k-1]-b[i+1]);
        }
        cout<<maxx+1<<" "<<r<<endl;
    }
    return 0;
}

原文链接: https://www.cnblogs.com/SyrupWRLD999/p/12923700.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    5.20 Vj F - Nastya and Door

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/349829

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午5:54
下一篇 2023年3月2日 上午5:55

相关推荐