1085. Perfect Sequence

来源:互联网 发布:dw for mac中文破解版 编辑:程序博客网 时间:2024/05/16 11:45

Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minimum numbers in the sequence, respectively.

Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence.

Input Specification:

Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (<= 105) is the number of integers in the sequence, and p (<= 109) is the parameter. In the second line there are N positive integers, each is no greater than 109.

Output Specification:

For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.

Sample Input:
10 82 3 20 4 5 1 6 7 8 9
Sample Output:

8

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <deque>
#include <queue>
#include <cstring>
#include <vector>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[10010];
int w[10010];
bool choice[10010][10010];
int cmp(int a,int b){return a > b;}
int main() {
    int n,i;
    long long p;
    cin>>n>>p;
    vector<long long>a(n);
    for(i=0;i<n;i++)
cin>>a[i];
sort(a.begin(),a.end());
int max=1;
int index=1;
int j,len,len1=1;
for(i=0;i<n;i++)
{
len=len1;
for(j=index;j<n;j++)
{
if(a[i]*p<a[j])
{
index=j;
len1=len-1;
break;
}
len++;
}
if(len>max)
max=len;
if(j==n)break;
}
cout<<max;
    return 0;
}

0 0