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. CentOS下编译Lua使得其支持动态链接

    在Linux下编译Lua时,我一般都是使用的make generic,这样编译没有什么问题,运行lua的程序也都OK,但是,这样在加载外部的C动态 链接库,却总是报下面的错误 dynamic libr ...

  2. ubuntu离线安装mysql

    一:ubuntu离线安装mysql 转载来源:https://blog.csdn.net/liuhuoxingkong/article/details/80696574 参考文章:https://ww ...

  3. Linux系统配置Java开发基本环境

    jdk安装一.用yum安装jdk1.查看yum库都有哪些jdk版本yum search java|grep jdk2.选择版本安装yum install java-1.8.0-openjdk(/usr ...

  4. P5468 [NOI2019]回家路线

    传送门 看题目一眼斜率优化,然后写半天调不出来 结果错误的 $dfs$ 有 $95$ 分?暴力 $SPFA$ 就 $AC$ 了? 讲讲正解: 显然是斜率优化的式子: 先不考虑 $q_{s_k}$ 的贡 ...

  5. angularjs calling order

    Here's the calling order: app.config()app.run()directive's compile functions (if they are found in t ...

  6. k3 cloud查看附件提示授予目录NetWorkService读写权限

    打开文件的时候出现下面的提示: 解决办法: 解决办法:找到C:\Program Files(x86)\Kingdee\K3Cloud\WebSite\FileUpLoadServices,在下面创建F ...

  7. Vue小白篇 - Vue介绍

    Vue ?啥是Vue?能干嘛? vue 的介绍 Vue 是一套用于构建用户界面的 渐进式框架 ,与其它大型框架不同的是, Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层 前端三大框 ...

  8. SIP UserAgent (B2BUA client)——libosip2 libeXosip2

    1. libosip2 libeXosip2 http://www.antisip.com/download/exosip2/ Features:--------eXosip2 has support ...

  9. zabbix入门之配置邮件告警

    zabbix入门之配置邮件告警 邮件环境搭建 使用本地邮箱账号发送邮件 zabbix-server 端安装 mailx .sendmail或者psotfix 服务,系统默认安装好了postfix #安 ...

  10. MySQL--14 半同步复制

    目录 MySQL半同步复制 半同步复制开启方法 测试半同步 MySQL过滤复制 MySQL半同步复制 从MYSQL5.5开始,支持半自动复制.之前版本的MySQL Replication都是异步(as ...