https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064

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 (≤10​5​​) is the number of integers in the sequence, and p (≤10​9​​) is the parameter. In the second line there are N positive integers, each is no greater than 10​9​​.

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 <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
long long a[maxn]; int main() {
int N, p, temp = 1;
scanf("%d%d", &N, &p);
for(int i = 1; i <= N; i ++)
scanf("%lld", &a[i]);
sort(a + 1, a + 1 + N);
for(int i = 1; i <= N; i ++) {
for(int j = temp + i; j <= N; j ++) {
if(a[j] <= a[i] * p)
temp = j - i + 1;
else break;
}
}
printf("%d\n", temp);
return 0;
}

  暴力 离考试越来越近 心慌慌

 

PAT 甲级 1085 Perfect Sequence的更多相关文章

  1. PAT甲级——A1085 Perfect Sequence

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

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

  3. PAT 1085 Perfect Sequence

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

  4. PAT 1085 Perfect Sequence[难]

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

  5. 1085 Perfect Sequence (25 分)

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

  6. pat甲级1085

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

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

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

  8. 1085. Perfect Sequence

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

  9. 1085 Perfect Sequence (25 分)

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

随机推荐

  1. Mysql千万级数据删除实操-企业案例

    某天,在生产环节中,发现一个定时任务表,由于每次服务区查询这个表就会造成慢查询,给mysql服务器带来不少压力,经过分析,该表中绝对部分数据是垃圾数据 需要删除,约1050万行,由于缺乏处理大数据的额 ...

  2. VC++ MFC单文档应用程序SDI下调用glGenBuffersARB(1, &pbo)方法编译通过但执行时出错原因分析及解决办法:glewInit()初始化的错误

    1.问题症状 在VC++环境下,利用MFC单文档应用程序SDI下开发OpenGL程序,当调用glGenBuffersARB(1, &pbo)方法编译通过但执行时出错,出错代码如下: OpenG ...

  3. OpenCV——归一化函数normalize

    函数原型: void cv::normalize(InputArry src,InputOutputArray dst,double alpha=1,double beta=0,int norm_ty ...

  4. switchable图片切换

    前提: 最近由于项目的需要jquery "switchable图片切换"效果 所以趁着周末有空时间研究下 ,以前工作都依赖于kissy框架,所以也没有综合的写过类似的,如下图所示效 ...

  5. PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  6. selenium自动化环境搭建(Windows)

    参考内容:虫师<selenium2自动化测试实战-基于python语言> 一.selenium介绍 selenium主要用于web应用程序的自动化测试,还支持所有基于web的管理任务自动化 ...

  7. Android Fragment(一)

    一.为什么要引入Fragments? 自从Android 3.0中引入fragments 的概念,可以译为:碎片.片段.其上的是为了解决不同屏幕分辩率的动态和灵活UI设计.大屏幕如平板小屏幕如手机,平 ...

  8. 【小程序】访问 https配置的数据接口

    小程序对于网络请求的URL的特殊要求:1)不能出现端口号;    2)不能用localhost;       3)  必须用https (一)搭建本地https服务器(windows) 搭建出来的服务 ...

  9. 20155211 网络对抗 Exp9 Web安全基础实践

    20155211 网络对抗 Exp9 Web安全基础实践 基础问题回答 SQL注入攻击原理,如何防御? 原理:SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语 ...

  10. 20155304《网络对抗》Exp4 恶意代码分析

    20155304<网络对抗>Exp4 恶意代码分析 实践内容 1.系统运行监控 1.1使用schtasks指令监控系统运行 我们在C盘根目录下建立一个netstatlog.bat的文本文件 ...