1085. Perfect Sequence (25)

简介: #include #include #include using namespace std;int main() { int n; long p; cin >> n >> p; v...
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    long p;
    cin >> n >> p;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());

    int result = 0, temp = 0;
    for (int i = 0; i < v.size(); i++) {
        for (int j = i + result; j < n; j++) {
            if(v[j] <= v[i] * p){
                temp = j - i + 1;
                if(temp > result) result = temp;
            }else break;
        }
    }

    cout << result << endl;

    return 0;
}

目录
相关文章
|
算法
LeetCode 128. Longest Consecutive Sequence
给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。
92 0
LeetCode 128. Longest Consecutive Sequence
LeetCode 367. Valid Perfect Square
给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。
100 0
LeetCode 367. Valid Perfect Square
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
117 0
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
108 0
|
C++
PAT (Advanced Level) Practice - 1038 Recover the Smallest Number(30 分)
PAT (Advanced Level) Practice - 1038 Recover the Smallest Number(30 分)
129 0
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
147 0
|
机器学习/深度学习 自然语言处理 算法框架/工具
Sequence to Sequence学习资料
Sequence to Sequence学习资料
113 0
【1085】Perfect Sequence (25 分)
【1085】Perfect Sequence (25 分) 【1085】Perfect Sequence (25 分)
98 0
|
算法
[LeetCode]--60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): 1."123" 2."132" 3
1082 1

热门文章

最新文章