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. Scala学习之路 (四)Scala的数组、映射、元组、集合

    一.数组 1.定长数组和变长数组 import scala.collection.mutable.ArrayBuffer object TestScala { def main(args: Array ...

  2. C++的技术探究

    C++深究 函数指针 double pam(int, double); // prototype double (*pf)(int, double); // declare function poin ...

  3. Jquery回到顶部功能

    问题描述: 在网页中,我们经常会由于网页内容过长,而需要在浏览网页时有一个快速回到网页顶部的功能,在浏览网页内容离顶部有一段距离时,出现快速回到网页顶部的工具,从而能使我们的网页更人性化. 问题的产生 ...

  4. A. Pride

    You have an array a with length n, you can perform operations. Each operation is like this: choose t ...

  5. 20155330 《网络攻防》 Exp4 恶意代码分析

    20155330 <网络攻防> Exp4 恶意代码分析 实验后回答问题 (1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操 ...

  6. Python基础(条件判断和循环) if elif else for while break continue;

    条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...

  7. MySQL优化:explain using temporary

    什么时候会使用临时表:group/order没设计好的时候 1.order没用索引 2.order用了索引, 但不是和where相同的索引 3.order用了两个索引, 但不是联合索引 4.order ...

  8. [arc102E]Stop. Otherwise...[容斥+二项式定理]

    题意 给你 \(n\) 个完全相同骰子,每个骰子有 \(k\) 个面,分别标有 \(1\) 到 \(k\) 的所有整数.对于\([2,2k]\) 中的每一个数 \(x\) 求出有多少种方案满足任意两个 ...

  9. 如何在web api中使用SignalR

    说明: 在webapi中使用signalr,使用IIS 环境: vs2012, .net4.5 第一步:建web api项目 第二步:nuget导入signalr Install-Package Mi ...

  10. Redis介绍及Jedis基础操作

    1.Redis简介 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes ...