1085 Perfect Sequence (25 分)

1085 Perfect Sequence (25 分)

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 (≤10​5​​) is the number of integers in the sequence, and p (≤10​9​​) is the parameter. In the second line there are N positive integers, each is no greater than 10​9​​.

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 8
2 3 20 4 5 1 6 7 8 9

Sample Output:

8

 

题⽬⼤意:给定⼀个正整数数列,和正整数p,设这个数列中的最⼤值是M,最⼩值是m,如果M <= m

* p,则称这个数列是完美数列。现在给定参数p和⼀些正整数,请你从中选择尽可能多的数构成⼀个

完美数列。输⼊第⼀⾏给出两个正整数N(输⼊正数的个数)和p(给定的参数),第⼆⾏给出N个正

整数。在⼀⾏中输出最多可以选择多少个数可以⽤它们组成⼀个完美数列

分析: 枚举所有的起点, 不断更新最大区间长度, 有个小优化 ,就是假设终点是 当前的起点 + 最大区间长度。

#include
using namespace std;
int a[100009];
int main() {
    long long int  n , p;
	cin>>n>>p;
	for( int i=0;i>a[i];
	} 
	sort(a,a+n);
	int ans = -1 ,cnt ;
	for( int i = 0;i

 

你可能感兴趣的:(PAT甲级)