【1085】Perfect Sequence (25 分)

简介: 【1085】Perfect Sequence (25 分)【1085】Perfect Sequence (25 分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
using namespace std;
const int maxn=100010;
int n,p,a[maxn];
int main(){   
  scanf("%d%d",&n,&p);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  sort(a,a+n);  //递增排序
  int ans=1; //最大长度,初值为1(表示至少有一个数)
  for(int i=0;i<n;i++){
    //key:在a[i+1]~a[n-1]中查找第一个超过a[i]*p的数字,返回其位置给j
    int j=upper_bound(a+i+1,a+n,(long long)a[i]*p)-a; //记得此处要减a!!!
    //注意upper_bound返回的是地址
    ans=max(ans,j-i); //更新最大长度
  }
  printf("%d\n",ans);  //输出结果
  system("pause");
    return 0;   
}
相关文章
UVa787 - Maximum Sub-sequence Product(最大连续乘积子串)
UVa787 - Maximum Sub-sequence Product(最大连续乘积子串)
51 0
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
106 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
128 0
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
113 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
116 0
【1140】Look-and-say Sequence (20分)
【1140】Look-and-say Sequence (20分) 【1140】Look-and-say Sequence (20分)
88 0
【1051】Pop Sequence (25 分)
【1051】Pop Sequence (25 分) 【1051】Pop Sequence (25 分)
111 0
1085. Perfect Sequence (25)
#include #include #include using namespace std; int main() { int n; long p; cin >> n >> p; v...
874 0