1085. Perfect Sequence (25)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng

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

提交代码

 #include<cstdio>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
long long line[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
long long n,p;
scanf("%lld %lld",&n,&p);
int i,j;
for(i=;i<n;i++){
scanf("%lld",&line[i]);
}
sort(line,line+n);
int amount;
long long cur=line[]*p;
for(j=;j<n&&line[j]<=cur;j++);//j指针
amount=j;
for(i=;i<n&&j<n;i++){//这里的j<n是为了避免不必要的循环
cur=line[i]*p;
for(;j<n&&line[j]<=cur;j++);
if(j-i>amount){
amount=j-i;
}
}
printf("%d\n",amount);
return ;
}

pat1085. Perfect Sequence (25)的更多相关文章

  1. 1085. Perfect Sequence (25) -二分查找

    题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  2. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  3. 1085 Perfect Sequence (25 分)

    Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...

  4. PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]

    题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...

  5. PAT甲级 Perfect Sequence (25) 记忆化搜索

    题目分析: 意思是要求对于一个给出的数组,我们在其中尽可能多选数字,使得所选数字的max <= min * p,而由于数据量较大直接二层循环不加优化实现是不现实的,由题意得知,对于数字序列的子序 ...

  6. 1085. Perfect Sequence (25)

    the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...

  7. PAT (Advanced Level) 1085. Perfect Sequence (25)

    可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...

  8. 1085. Perfect Sequence (25)-水题

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. 【PAT甲级】1085 Perfect Sequence (25 分)

    题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...

随机推荐

  1. Velocity的layout功能

    一.从VelocityViewServlet到VelocityLayoutServlet 使用Velocity开发web应用时,需要在web.xml中配置一个Velocity提供的VelocityVi ...

  2. bzoj2118

    最短路 很早以前做的了 数据范围太大,不能直接算 mn=min(a[i]) 算出d[i]表示sum%mn=i最小能构成的数,这个用最短路就行了,然后计算d[i],d[i]+mn的个数统计答案 #inc ...

  3. R: 缺失值 & 查看变量类型

    ################################################### 问题:缺失值   18.5.2 有关处理缺失值的各种方法有什么?各自的适用场景. 解决方案: n ...

  4. 7、sraToolkit安装使用

    参考:http://blog.csdn.net/Cs_mary/article/details/78378552        ###prefetch 参数解释 https://www.ncbi.nl ...

  5. ARC097C K-th Substring

    传送门 题目 You are given a string s. Among the different substrings of s, print the K-th lexicographical ...

  6. PAM认证

    PAM认证 摘自: http://www.cnblogs.com/shenxm/p/8451889.html PAM(Pluggable Authentication Modules) Sun公司于1 ...

  7. EF Code first 和 DDD (领域驱动设计研究)系列一

    在上个公司工作时,开发公司产品的过程中,接触到了EF Code first. 当时,整个产品的架构都是Lead developer设计建立的,自己也不是特别理解,就赶鸭子上架跟着一起开发了. 现在回过 ...

  8. jQuery学习1

    学习jQuery的过程中发现了一个博客把jquery的要点整理的很不错,摘抄其精华以备学习.感谢:http://blog.csdn.net/wph_1129/article/details/59932 ...

  9. NPOI office操作

    写excel FileStream file = new FileStream(@"test.xls",FileMode.Create); hssfworkbook.write(f ...

  10. SpringBoot第六篇:整合通用Mapper

    作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10876339.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言   在以往的项 ...