编程语言
首页 > 编程语言> > 用LUA(和C++)刷PAT (Advanced Level) ——1085 Perfect Sequence

用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;
}

标签:Perfect,1085,end,int,start,numbers,PAT,include,itr
来源: https://blog.csdn.net/weixin_44316978/article/details/120091919