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

知识点:

剪枝,遍历的时候,如果 list[i]*p < list[j] 的话,就剪枝

另外,比当前完美序列长度小的就不用遍历了,j 直接从 i+cnt 开始

 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std; int main(){
vector<int> list;
long long p,tmp;
int n; scanf("%d %lld",&n,&p); for(int i=;i<n;i++){
scanf("%lld",&tmp);
list.push_back(tmp);
}
sort(list.begin(),list.end()); int cnt=; for(int i=;i<n;i++){
for(int j=i+cnt;j<n;j++){
if(list[i]*p>=list[j]){
if(j-i>cnt)
cnt=j-i;
}else{
break;
}
}
}
printf("%d",cnt+);
}

1085. Perfect Sequence的更多相关文章

  1. 1085 Perfect Sequence (25 分)

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

  2. PAT 1085 Perfect Sequence

    PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...

  3. PAT 1085 Perfect Sequence[难]

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

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

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

  5. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  6. 1085 Perfect Sequence (25 分)

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

  7. 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 ...

  8. 1085. Perfect Sequence (25)

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

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

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

随机推荐

  1. oracle学习之数据库数据保存成文件

    常常需要将数据库中的数据生成文档,由于比较喜欢脚本的方式,所以就需要使用spool的时候进行格式设置,以下简单整理了一下oracle中进行格式设置的一些东西,一共十八条,其实常用的也就那么几个,稍后会 ...

  2. threejs指定对象旋转中心

    指定对象旋转中心 默认情况下,对象的旋转中心都是自身的中心.对于组对象而言,也是如此.因此,可以利用这个特点,实现对象绕任何点旋转,也就是指定旋转中心.比如我们想要下图的对象绕A点旋转  我们可以添加 ...

  3. css 边距等常用设置

    前端知识 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  4. JAVA课堂练习-动手动脑--数组

    1.阅读并运行示例PassArray.java,观察并分析程序输出的结果,小结,然后与下页幻灯片所讲的内容进行对照. 源代码: public class PassArray { public stat ...

  5. 8K - 圆桌会议

    HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有解决不了的问题,这也只有HDU A ...

  6. visual studio 2017 30天到期,不能输入注册码

    官网下载了visual studio 2017后,第一次安装没有登陆,导致只有30天试用期,虽然还在试用期内,但是无法使用注册码永久使用 解决办法: 1.注册一个微软账号,直接百度搜索“微软账号登陆” ...

  7. 虚拟机vmware centos7 扩展磁盘空间

    0.思路 创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用 1.准备 1.1 注意使用VMware自带 ...

  8. java读取properties文件时候要注意的地方

    java读取properties文件时,一定要注意properties里面后面出现的空格! 比如:filepath = /home/cps/ 我找了半天,系统一直提示,没有这个路径,可是确实是存在的, ...

  9. for 循环分解

    for (expression1; expression2; expression3) { statement; } statement称为循环体 expression1为初始化部分,只在循环开始前执 ...

  10. There are stopped jobs

    问题背景 系统:ubuntu,当输入exit退出shell时,出现There are stopped jobs 无法退出shell 解决办法 找到这个stopped job然后终止它 jobs 或者 ...