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刚启动就停止是什么原因

    1.找到mysql安装目录,将其配置文件my.default.ini改名为my.ini,并且将my.ini移至bin目录下. 2.启动命令行,将目录切换到mysql安装目录的bin目录下.3.接下来, ...

  2. docker安装jenkins及其相关问题解决

    1.拉取镜像并启动容器 docker run -d -p 8080:8080 -p 50000:50000 -v $(pwd)/data:/var/jenkins_home --name jenkin ...

  3. 装饰器 python 你也可以叫语法糖

    1.最简单的装饰器不带入参 def  func(): pass def  decorate(func) def wrapper(): return func() return wrapper 使用 @ ...

  4. Android Des加密解密

    算法转自:http://www.linuxidc.com/Linux/2011-08/41866.htm import java.security.Key; import java.security. ...

  5. 【LeetCode5】Longest Palindromic Substring★★

    1.题目描述: 2.解题思路: 题意:求一个字符串的最长回文子串. 方法一:中心扩展法.遍历字符串的每一个字符,如果存在回文子串,那么中心是某一个字符(奇数)或两个字符的空隙(偶数),然后分两种情况( ...

  6. 大数据入门第二十三天——SparkSQL(二)结合hive

    一.SparkSQL结合hive 1.首先通过官网查看与hive匹配的版本 这里可以看到是1.2.1 2.与hive结合 spark可以通过读取hive的元数据来兼容hive,读取hive的表数据,然 ...

  7. [CF986F]Oppa Funcan Style Remastered[exgcd+同余最短路]

    题意 给你 \(n\) 和 \(k\) ,问能否用 \(k\) 的所有 \(>1\) 的因子凑出 \(n\) .多组数据,但保证不同的 \(k\) 不超过 50 个. \(n\leq 10^{1 ...

  8. 微服务监控zipkin、skywalking以及日志ELK监控系列

    0.整体架构 整体架构目录:ASP.NET Core分布式项目实战-目录 一.目录 1.zipkin监控 2.skywalking监控 3.ELK日志监控 asp.net Core 交流群:78746 ...

  9. 微信小程序实现各种特效实例

    写在前面 最近在负责一个微信小程序的前端以及前后端接口的对接的项目,整体上所有页面的布局我都已经搭建完成,里面有一些常用的特效,总结一下,希望对大家和我都能有所帮助 实例1:滚动tab选项卡 先看一下 ...

  10. jquery原理的简单分析,让你扒开jquery的小外套。

    引言 最近LZ还在消化系统原理的第三章,因此这部分内容LZ打算再沉淀一下再写.本次LZ和各位来讨论一点前端的内容,其实有关jquery,在很久之前,LZ就写过一篇简单的源码分析.只不过当时刚开始写博客 ...