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. java web基础学习 Forward和Redirect区别

    Forward和Redirect代表了两种请求转发方式:直接转发和间接转发.对应到代码里,分别是RequestDispatcher类的forward()方法和HttpServletRequest类的s ...

  2. [poj1390]Blocks(方块消除)

    题目大意:给定一序列,可点击某一位置消除与其相邻且相同的方块,得分为$len*len$,求最大得分. 解题关键:关键是状态的构造,首先离散化一下,令$dp[i][j][k]$表示序列$i-j$且后面有 ...

  3. Arcane Numbers 1

    Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...

  4. [HDU1003]最长子序列和

    http://acm.hdu.edu.cn/showproblem.php?pid=1003 解题关键:1.最大连续子序列和模板 2.max.end不能使用,在oj中会显示编译错误 3.注意模板中没有 ...

  5. This account is currently not available

    今天在linux下切换用户发现提示This account is currently not available,说是无效用户了后来网上查了一下发现是用户的shell禁止登录了,解决方法只要开启she ...

  6. 具体问题:3、hibernate跟Mybatis/ ibatis 的区别,为什么选择?

    第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀 ...

  7. Asp.net 微信企业号网页开发流程

    一.在pageload方法中获取code var code = GetCode(); private string GetCode() { return HttpContext.Current.Req ...

  8. Vmware克隆Centos 不能上网的解决方案

    问题:用Vmware克隆Centos 6.4后,发现系统内只有eth1,而且/etc/sysconfig/network-scripts/下只有,ifcfg-eth0文件,虽然可以上网,但无法设置静态 ...

  9. 使用Paramiko的问题

    在使用Paramiko远程登录的时候,会报sudo: sorry, you must have a tty to run sudo 切换到root用户,使用visudo命令,然后就会打开一个文本,在文 ...

  10. 【mybatis-SqlSession的方法总结】

    SqlSession 实例在 MyBatis 中是非常强大的一个类.SqlSession 实例中有所有执行语句的方法,提交或回滚事务,还有获取映射器实例. 在 SqlSession 类中有超过 20 ...