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. css3 tranform perspective属性

    perspective 属性用于规定观察点距离元素的距离, 1 观察点距离元素越近,元素变形就越大,灭点距离越近. 2 观察点距离元素越远,元素变形越小,灭点距离也就越远. 比如设置perspecti ...

  2. RESTEasy常用注解

    一.@Path,标注资源类或方法的相对路径          Path参数的形式有三种:          1.固定值          2.纯正则表达式          3.固定值和正则表达式的混 ...

  3. js拼的onclick调用方法需要注意的地方 之一

    1.首先,明确一点,js方法中参数可以传递字符串,对象,number类型等,对象传递的是引用,方法中修改了,会影响到方法外面的对象. 2.下面重现项目中遇到的一个问题:(其实就是要明白通过引号来拼接字 ...

  4. tomcat 自带jdk

    http://blog.csdn.net/b452608/article/details/70143466

  5. (cdh)hive 基础知识 名词详解及架构

    过程 启动 hive 之后出现的 CLI 是查询任务的入口,CLI 提交任务给 Driver Driver 接收到任务后调用 Compiler,Executor,Optimizer 将 SQL 语句转 ...

  6. Break 、Continue 和ReadOnly、Const和Ref和Out params

    Break和Continue区别 之前对于Break和Continue:ReadOnly和Const:ref和out,params之类的基础东东学习过,但是一直没有仔细去研究到底是怎么一回事儿,最近在 ...

  7. shell if的使用

    1 字符串判断 str1 = str2 当两个串有相同内容.长度时为真 str1 != str2 当串str1和str2不等时为真 -n str1 当串的长度大于0时为真(串非空) -z str1 当 ...

  8. zookeeper-3.4.5-cdh5.1.0 完全分布式安装

    1.环境 主机名 IP地址 JDK ZooKeeper myid c1 192.168.58.129 1.7.0_11 server.1 1 c2 192.168.58.130 1.7.0_11 se ...

  9. 【关于安装mysql5.6的一些问题总结】

    1:安装msyql5.6介质(mysql-5.6.24-winx64.msi)以后没有myslq服务: 解决: 管理员身份cmd进入bin目录: mysqld.exe -install Service ...

  10. 【leetcode 114. 二叉树展开为链表】解题报告

    思路:递归,将左子树变成单链表形式,再将右子树变成单链表形式,最后将左子树单链表的末端连接到右子树单链表表头,将根节点的左孩子置空 void flatten(TreeNode* root) { if ...