用LUA(和C++)刷PAT (Advanced Level) ——1085 Perfect Sequence

2021/9/4 1:07:21

本文主要是介绍用LUA(和C++)刷PAT (Advanced Level) ——1085 Perfect Sequence,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int N, P, Max = 0;
    cin>>N>>P;
    vector<long long int> numbers(N);
    for(int i = 0; i < N; i++)
        scanf("%d", &(numbers[i]));
    sort(numbers.begin(), numbers.end());
    auto end_itr = numbers.begin();
    for(auto start_itr = numbers.begin(); start_itr != numbers.end(); start_itr ++){
        long long int limit = *start_itr * P;
        while(end_itr != numbers.end() && *end_itr <= limit)
            end_itr ++;
        Max = max(Max, (int)(end_itr-start_itr));
    }
    cout<<Max<<endl;
}


这篇关于用LUA(和C++)刷PAT (Advanced Level) ——1085 Perfect Sequence的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程