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. Linux下Python2升级Python3

    Linux下Python2的升级方法: 一.下载Python3安装包: 1.在线下载 wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2 ...

  2. golang sync.Pool包的使用和一些注意地方

    package main; import ( "sync" "fmt" "net" "runtime" ) //sync ...

  3. socketv 验证客户端链接的合法性

    一 .socketv 验证客户端链接的合法性 send()与sendall() 验证客户端 加密验证 如果你想在分布式系统中实现一个简单的客户端链接认证功能,又不像SSL那么复杂,那么利用hmac+加 ...

  4. MongoDb进阶实践之八 MongoDB的聚合初探

    一.引言 好久没有写东西了,MongoDB系列的文章也丢下好长时间了.今天终于有时间了,就写了一篇有关聚合的文章.一说到“聚合”,用过关系型数据库的人都应该知道它是一个什么东西.关系型数据库有“聚合” ...

  5. docker从私有镜像库pull/push镜像问题:Error response from daemon: Get https://xxxx.com/: x509: certificate signed by unknown authority

    docker从私有镜像库pull/push镜像问题:Error response from daemon: Get https://harbor.op.xxxx.com/v2/: x509: cert ...

  6. RabbitMQ 的基本介绍

    RabbitMQ官网教程:http://www.rabbitmq.com/getstarted.html RabbitMQ 是一个由 Erlang 语言开发的 AMQP 的开源实现.AMQP :Adv ...

  7. JVM 体系结构概述 (一)

    一.jvm运行在操作系统之上的,它与硬件没有直接交互: 二.JVM体系结构概览 JVM的基本结构:类加载器.执行引擎.运行时数据区.本地方法接口: 过程:class文件 ----> 类加载器 - ...

  8. gulp ( http://markpop.github.io/2014/09/17/Gulp入门教程 )

    前言 最近流行前端构建工具,苦于之前使用Grunt,代码很难阅读,现在出了Gulp,真是摆脱了痛苦.发现了一篇很好的Gulp英文教程,整理翻译给大家看看. 为什么使用Gulp Gulp基于Node.j ...

  9. Spring MVC 请求处理方法

    以下两种都可以处理用户请求,但请求处理方法值得是第二种 1. SpringMVC 提供的 Controller 接口中公开的 ModelAndView handleRequest(request, r ...

  10. c++11 并发 条件变量 超时等待的代码练习

    资料地址 http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until http://www.cnblogs.com/ha ...