1085. Perfect Sequence (25)
来源:互联网 发布:谷歌读屏软件下载 编辑:程序博客网 时间:2024/06/05 05:00
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 82 3 20 4 5 1 6 7 8 9Sample Output:
8#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<algorithm>using namespace std;const int maxn=1000007;typedef long long ll;template<class T>inline T read(T&x){ char c; while((c=getchar())<=32); bool f=false; if(c=='-')f=true,c=getchar(); for(x=0; c>32; c=getchar())x=x*10+c-'0'; if(f)x=-x; return x;}template<class T>inline void write(T x){ if(x<0)putchar('-'); else if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0');}template<class T>inline void writeln(T x){ write(x); puts("");}//--------IO template--------------------ll a[maxn];int n;int bin_ser(ll x)//二分查找{ int left=0,right=n-1; while(left<=right) { int mid=(left+right)>>1; if(a[mid]==x)return mid; else if(x<a[mid])right=mid-1; else left=mid+1; } return left-1;//没有的话,返回当前的位置}//不需要输入输出优化,只是自己这样写比较方便 int main(){ int m,i,j,k,t; ll p; read(n);read(p); for(i=0;i<n;i++)read(a[i]); if(p<0){write(0);return 0;} sort(a,a+n); i=0; //while(a[i]*p<a[n-1])i++;write(n-i)///这样写只有一个case过不去,明显数据还是比较弱的 int ans=1; for(i=0;i<n;i++) { ll x=p*a[i]; int index=bin_ser(x);//二分枚举 ans=max(index-i+1,ans); } writeln(ans); return 0;}
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- 1085. Perfect Sequence (25)
- UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)
- Android学习总结八:Cursor游标
- oracle 11g 64位安装32位客户端和PL/SQL
- Ubuntu下配置samba实现文件夹共享
- MATLAB入门教程
- 1085. Perfect Sequence (25)
- Android XListView实现原理讲解及分析
- 对话框添加菜单
- CCLableIBMFont 操作文本中单个字符
- OpenCv_Image与光流法中设置ROI区域
- java socket编程
- TCP/IP
- 实现sqrt()开方运算
- android上运行python