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)。
88 0
LeetCode 128. Longest Consecutive Sequence
【1085】Perfect Sequence (25 分)
【1085】Perfect Sequence (25 分) 【1085】Perfect Sequence (25 分)
89 0
HDOJ 1005 Number Sequence
HDOJ 1005 Number Sequence
101 0
uva 10706 - Number Sequence
点击打开链接uva 10706 题目意思:    有一个数组 s[1] = 1 , s[2] = 1 2 , .......s[k] = 1....k,要求给定一个n表示数组的第几位,要求这个第几位是什么数。
951 1
|
算法 C#
算法题丨Longest Consecutive Sequence
描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
1117 0
|
机器学习/深度学习 自然语言处理 算法
|
C++
[LeetCode] Binary Tree Longest Consecutive Sequence
Problem Description: Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from so...
909 0
下一篇
无影云桌面