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. 基于各种基础数据结构的SPFA和各种优化

    一.基于各种数据结构的SPFA 以下各个数据均为不卡SPFA的最短路模板:P3371 [模板]单源最短路径(弱化版)的测试时间 1.STL队列:用时: 1106ms / 内存: 8496KB #inc ...

  2. Linux学习之文件搜索命令

    一.文件搜索命令locate locate 文件名 在后台数据库中按文件名搜索,搜索速度最快 /var/lib/mlocate #locate命令所搜索的后台数据库(数据库不会实时刷新,所以新建的文件 ...

  3. Mysql命令收集【重要】

    1.在linux上获取Mysql服务器状态,及版本: [root@host]# mysqladmin --version 结果信息: mysqladmin  Ver 8.42 Distrib 5.7. ...

  4. owaspbwa tickets

    owaspbwa tickets 来源  https://sourceforge.net/p/owaspbwa/tickets/ 192 SQL Injection in pic_id paramet ...

  5. ActiveMQ的简单使用

    项目中使用的介绍 一.运行ActiveMQ 在文件路径下...\apache-activemq-5.13.3\bin\win64 运行activemq.bat 这是系统中的使用,运行后还可以访问相应的 ...

  6. apt-get update 101错误解决办法

    在一次装好Ubuntu系统, 执行 sudo apt-get update 时,报了错 " W: Failed to fetch http://security.ubuntu.com/ubu ...

  7. [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter 解决

    错误:/usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 解决:是因为64位系 ...

  8. LINUX Mysql5.6.19 安装

    1.需要扩展安装 yum -y install make bison gcc-c++ cmake ncurses ncurses-devel 2.下载Mysql5.6.19 wget ftp://mi ...

  9. SPOJ1693 COCONUTS - Coconuts

    传送门[洛谷] 自闭QAQ 什么玩意QAQ 不是很理解到底在干啥 问了巨佬以后大概是这个样子的 可以看出是最小割模型 对于每一个人 反悔的话就是代价+1 那么连接(s,i) (i,t)分别表示他最后选 ...

  10. java object bean 转map

    import java.lang.reflect.Field; /** * obj-->map * ConvertObjToMap * 2016年8月17日上午10:53:59 * @param ...