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. bootstrap collapse 无法收回

    $(function () { //修复collapse不能正常折叠的问题 $(".collapsed").click(function () { var itemHref = $ ...

  2. vuex写法

    <template> <div class="hello"> <p>{{count}}</p> <p> <butt ...

  3. python tcp 粘包问题解决、文件下载等

    from socket import * #以下是关于tcp:服务端 和 客户端的小例子#服务端socket_server = socket(AF_INET, SOCK_STREAM) socket_ ...

  4. 软件开发中 SQL SERVER 任务的用法

    在软件开发中,经常性会用到定时任务.这个时候你可能会想到线程.但是事实中,线程方法比较麻烦.容易出错,资源竞争等问题,设计起来让你很头痛. 现在给大家提供一个新的思路,用SQL SERVER 的任务管 ...

  5. PAT 1026 程序运行时间(15)(C++&Java&Python)

    1026 程序运行时间(15)(15 分) 要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间 ...

  6. 洛谷1894 [USACO4.2]完美的牛栏The Perfect Stall

    原题链接 二分图最大匹配板子. 每个奶牛向它愿意去的牛棚连边,跑二分图最大匹配即可. 这里我用的是匈牙利算法. #include<cstdio> #include<cstring&g ...

  7. BZOJ1093或洛谷2272 [ZJOI2007]最大半连通子图

    BZOJ原题链接 洛谷原题链接 和 Going from u to v or from v to u?(题解)这道题类似,只不过是求最大子图的大小和个数而已. 一样用\(tarjan\)求强连通分量, ...

  8. java中的内存模型

    概述 Java平台自动集成了线程以及多处理器技术,这种集成程度比Java以前诞生的计算机语言要厉害很多,该语言针对多种异构平台的平台独立性而使用的多线程技术支持也是具有开拓性的一面,有时候在开发Jav ...

  9. ubuntu12.04下Qt调试器的使用

    最近,我一直在用Qt编写C++程序,但在编写过程中遇到了问题,想用Qt Creator中的调试器调试一下,但调试时(在Qt Creator中已配置好相应的调试器)出现“ ptrace:Operatio ...

  10. linux-ubuntu 下R无法安装rjava模块的原因及解决方案

    错误信息: 没有 /usr/lib/jvm/default-java/jre/bin/java 原因: R找不到java作为依赖 解决方案: (1) 如果你没有安装java,请先安装java. (2) ...