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. N皇后问题 各种优化

    0.问题引入 N皇后问题是一个经典的问题,在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行.同一列.同一斜线上的皇后都会自动攻击),问有多少种摆法. 题目链接:https://ww ...

  2. App常见产品问题及预防方法

    01界面适配 a:手机分辨率为1920x7080的高分辨率手机,在调整手机字体大小时,会导致页面显示出现变形: b:因用户设置的特殊字体导致列表的字母条不显示: c:某些banner 图片在部分机型只 ...

  3. 关于 Spring AOP (AspectJ) 该知晓的一切

    关联文章: 关于Spring IOC (DI-依赖注入)你需要知道的一切 关于 Spring AOP (AspectJ) 你该知晓的一切 本篇是年后第一篇博文,由于博主用了不少时间在构思这篇博文,加上 ...

  4. 真实的物理机安装Centos7系统后网卡只有lo没有eno1的解决办法:实际上是物理机未安装网驱动卡

    问题症状: 我真实的物理机安装Centos7系统后,在/etc/sysconfig/目录下查看,发现网卡只有lo没有eno1,出现该问题的实际原因是物理机未安装网驱动卡. 解决办法: 不多说了,让我们 ...

  5. create_buffer_tree example

    假设这样一种情况: 绕线完修完timing 后,designer 修改了netlist,给了eco.v,其中改动了 clock tree 的一个分支,导致这个分支上的buffer 都没有了,如下图 一 ...

  6. input输入框的光标定位的问题

    input输入框的光标定位的问题 在给input输入框赋值的时候,或者在我之前写模拟下拉框js组件的时候,时不时会碰到光标的小bug问题,比如键盘中的 上移或者下移操作,在浏览器中光标会先移到最前端, ...

  7. JAVA 框架 springmvc controller的返回值

    一.返回值:ModleView对象. 使用modelAndView.setViewName设置返回的页面.使用modelAndView.addObject设置返回的数据. @RequestMappin ...

  8. zabbix部署(1)(lnmp转)

    1.lnmp 首先 确保CentOS7上网络配置正确,可以正常访问互联网. 确保已经关闭了iptables. CentOS7上是firewall,关闭命令: 1 2 # systemctl stop  ...

  9. ISCSI工作流程target和initiator

    随着企业级的数据呈指数增长,传统的集中式存储方案已无法满足其存储要求,因而存储区域网(storage area network,SAN)技术被广泛应用,但其存在距离短.价格贵和构建复杂等不足.基于iS ...

  10. mfc CListBox

    通过ID操作对象 CListBox(列表框)控件 CListBox类常用成员 CListBox插入数据 CListBox删除数据 CListBox运用示例 一.CListBox类常用成员 CListB ...