Source:

PAT A1085 Perfect Sequence (25 分)

Description:

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

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

Keys:

  • 双指针

Code:

 #include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e5+;
typedef long long LL; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE LL n,p,s[M];
scanf("%lld%lld", &n,&p);
for(LL i=; i<n; i++)
scanf("%lld", &s[i]);
sort(s,s+n);
LL i=,j=,step=;
while(j < n)
{
while(j<n && s[j]<=s[i]*p)
j++;
if(j-i > step)
step = j-i;
i++;
j=i+step;
}
printf("%lld", step); return ;
}

PAT_A1085#Perfect Sequence的更多相关文章

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

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

  2. A1085. Perfect Sequence

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

  3. 1085. Perfect Sequence

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

  4. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  5. 1085 Perfect Sequence (25 分)

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

  6. PAT 1085 Perfect Sequence

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

  7. PAT 1085 Perfect Sequence[难]

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

  8. pat1085. Perfect Sequence (25)

    1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Give ...

  9. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

随机推荐

  1. forEach究竟能不能改变数组的值

    forEach究竟能不能改变数组的值 :https://blog.csdn.net/ZhengKehang/article/details/81281563 初学者每次提到Array对象的时候有些烦人 ...

  2. bfs(双向bfs加三维数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 MS (Java/Others)     ...

  3. python学习二十三天函数的定义

    在计算机编程中,函数就是可以重复调用,可以传递参数,减少代码的量,可以高效写出好的代码,提高软件的运行质量,下面简单讲述python函数的定义方式 1,函数的定义 函数的定义用关键词def  函数名跟 ...

  4. App.Config操作

    public class ConfigUtils { public static string filename = System.Windows.Forms.Application.StartupP ...

  5. 机器学习-线性回归补充-R^

    线性回归算法在选自变量会遇到两个问题:一是去掉多重共线性干扰,二是选择最优自变量组合. 线性回归步骤 1.选择自变量 注意点 去掉多重共线性干扰,选择最优自变量组合.这里需要理解决定系数:R^.它是理 ...

  6. C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable

    C++中使用函数strcpy时出现问题: 解决方案: 在文件开头添加语句: #pragma warning(disable:4996) done! 剑指offer: 第一题:赋值运算符函数 #incl ...

  7. 《YC创业营:硅谷顶级创业孵化器如何改变世界》:YC2011批量天使投资记录 三星推荐

    这个YC创业营是一个硅谷的天使投资基金,每年两次批量投资创业公司.本书说的是2011年YC批量选择了64个创业团队,让他们集中到硅谷办公3个月,给他们创业指导,帮他们找A轮投资. YC创始人偏爱25岁 ...

  8. 【LeetCode】随机化算法 random(共6题)

    [384]Shuffle an Array(2019年3月12日) Shuffle a set of numbers without duplicates. 实现一个类,里面有两个 api,struc ...

  9. Jmeter —— Test Fragment (测试片段)

    Test Fragment(测试片段) 1.    概念 JMeter中的Test Fragent:是控制器上一种特殊的线程组:它在测试树上与线程组处于同一个层级.但是使用的时候需要和Include ...

  10. C#基础提升系列——C#集合

    C#集合 有两种主要的集合类型:泛型集合和非泛型集合. 泛型集合被添加在 .NET Framework 2.0 中,并提供编译时类型安全的集合. 因此,泛型集合通常能提供更好的性能. 构造泛型集合时, ...