用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;
}
上一篇:RabbitMQ学习笔记


下一篇:10组-Alpha冲刺-5/6