1030. 完美數列(25)
給定一個正整數數列,和正整數p,設這個數列中的最大值是M,最小值是m,如果M <= m * p,則稱這個數列是完美數列。
現在給定參數p和一些正整數,請你從中選擇儘可能多的數構成一個完美數列。
輸入格式:
輸入第一行給出兩個正整數N和p,其中N(<= 105)是輸入的正整數的個數,p(<= 109)是給定的參數。第二行給出N個正整數,每個數不超過109。
輸出格式:
在一行中輸出最多可以選擇多少個數可以用它們組成一個完美數列。
輸入樣例:10 8 2 3 20 4 5 1 6 7 8 9輸出樣例:
8
#include <cstdio>
#include <algorithm>
using namespace std;
int a, res = 1;
double b,temp=0,c[100001];
int main(){
scanf("%d %lf",&a,&b);
for(int i = 0;i < a;i++){
scanf("%lf", &c[i]);
}
sort(c, c+a);
for(int i = 0; i < a; i++){
for(int j = i + res - 1; j < a; j++){
if(c[j]<=c[i]*b){
if(j + 1 - i>res){
res = j - i +1;
}
}else{
break;
}
}
}
printf("%d",res);
return 0;
}