当前位置:网站首页>Pat 1085 perfect sequence (25 points) perfect sequence

Pat 1085 perfect sequence (25 points) perfect sequence

2022-07-06 20:50:00 Python ml

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
       
    int n,maxnum=0;
    long long p;
    cin>>n>>p;
    vector<int>a(n);
    for(int i=0;i<n;i++){
    
        scanf("%d",&a[i]);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
                    // Determine the minimum value m
        for(int j=i+maxnum;j<n;j++){
    
            if (a[j] <= a[i] * p) {
    
                maxnum=max(j-i+1,maxnum);
            }else break;
        }
    }
    cout<<maxnum;
    system("pause");
    return 0;
}
原网站

版权声明
本文为[Python ml]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131147469002.html