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 (≤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 8
2 3 20 4 5 1 6 7 8 9
Sample Output:
8
注意点:1.int*int 的范围必须用long long;
2.if(a[n-1]<=x) return n;
#include<bits/stdc++.h>
using namespace std; const int maxn =; int a[maxn]; int n,p; int binary_Search(int i,long long x){ if(a[n-]<=x)
return n; int left=i+,right=n-; while(left<right){
int mid = (left+right)/; if(a[mid]>x){
right =mid;
}else{
left= mid+;
}
} return left; } int main(){ cin>>n>>p; for(int i=;i<n;i++)
cin>>a[i]; sort(a,a+n); int ans=; for(int i=;i<n;i++){ // int j=binary_Search(i,(long long)a[i]*p); int j=upper_bound(a+i+,a+n,(long long)a[i]*p)-a; ans=max(ans,j-i); // cout<<j<<" "<<i<<endl;
} cout<<ans<<endl; return ; }
最新文章
- Fedora 23 忘记root密码
- 区间重叠计算及IntervalTree初识
- 用Python套接字创建HTTP客户与服务器程序
- AgileEAS.NET SOA 中间件2013第四季度发布&;部分功能开源预告
- 最新版ffmpeg源码分析
- js倒计时防页面刷新
- Java基础之写文件——从多个缓冲区写(GatheringWrite)
- fl,flash,mx包的区别
- 得到当前网址的域名 ASP.NET
- TableView 多余分割线的处理
- EDP转换IC NCS8801S:RGB/LVDS转EDP芯片
- 201521123102 《Java程序设计》第1周学习总结
- 如何解决在ie下,Echarts多次使用setOption更改数据时,数据错乱问题
- linux下的$0-n作用
- Excel转datatable
- iframe和ajax文件上传方法
- html可用于跨域的三个标签
- lombok 一个不错的小工具
- winform TreeView 节点选择
- 170605、防止sql注入(二)
热门文章
- 7.使用mysql_export监控mysql
- 25. Postman的使用
- upc组队赛1 小C的数学问题【单调栈】(POJ2796)
- Idea添加Tomcat
- nginx中root与alias关键字的区别
- Linux 2.6.x fs/pipe.c local kernel root(kit?) exploit (x86)
- ArcGis 创建Annotation注记要素类、添加注记要素 并加载到Activeview AO C#
- EXCEL数据计算不准确的问题
- sysprep
- 互斥量mutex简介