2017浙江工业大学-校赛决赛 小马哥和数列

Description

小马哥是个追求完美的人,现在给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美的,现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。

Input

多组数据。输入第一行给出两个正整数N和p,其中N(<= 10^5)是输入的正整数的个数,p(<= 10^9)是给定的参数。第二行给出N个正整数,每个数不超过10^9。

Output

在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。

Sample Input

10 3
1 2 4 3 10 9 8 7 6 5

Sample Output

7
解法:二分查一查就好啦
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <vector>
 4 #include <queue>
 5 #include <math.h>
 6 #include <algorithm>
 7 #define N 100005
 8 #define LL long long
 9 using namespace std;
10 struct Node{
11     double x,y;
12     double ans;
13 }node[N],Nod[N];
14 double Dis(Node x,double a,double b){
15     return sqrt((x.x-a)*(x.x-a)+(x.y-b)*(x.y-b));
16 }
17 bool Sort(Node a,Node b){
18     if(a.ans==b.ans){
19         return a.x<b.x;
20     }
21     return a.ans<b.ans;
22 }
23 LL a[123456];
24 int main(){
25     LL n,k;
26     while(cin>>n>>k){
27        for(int i=1;i<=n;i++){
28             cin>>a[i];
29        }
30        sort(a+1,a+1+n);
31        LL Max=-1;
32        for(int i=1;i<=n;i++){
33             LL pos=a[i]*k;
34             int ans=upper_bound(a+1,a+1+n,pos)-a-1;
35             Max=max((LL)ans-i+1,Max);
36        }
37        printf("%d
",Max);
38     }
39     return 0;
40 }
原文地址:https://www.cnblogs.com/yinghualuowu/p/7359059.html