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

又是没看清题,这道题的子序列不需要是原来的连续子序列,只要求是原来里面的值就行,搞得又浪费了很多时间!!!!
 //靠,不需要是子排序,就是找数字就行
#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;
int N;
long long P;
int main()
{
cin >> N >> P;
vector<int>num(N);
for (int i = ; i < N; ++i)
cin >> num[i];
sort(num.begin(), num.end());
int res = ;
for(int L=,R=;L<=R && R<N;++R)
{
while (L <= R && num[R] > P * num[L])
L++;
res = res > R - L + ? res : R - L + ;
}
cout << res << endl;
return ;
}

PAT甲级——A1085 Perfect Sequence的更多相关文章

  1. PAT 甲级 1085 Perfect Sequence

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

  2. A1085. Perfect Sequence

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

  3. 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 ...

  4. PAT 甲级 1051 Pop Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...

  5. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  6. PAT甲级——A1051 Pop Sequence

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

  7. PAT甲级——1140.Look-and-say Sequence (20分)

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

  8. PAT_A1085#Perfect Sequence

    Source: PAT A1085 Perfect Sequence (25 分) Description: Given a sequence of positive integers and ano ...

  9. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. LeetCode 67. Add Binary【个位补0,不必对齐】【easy】

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  2. linux格式化磁盘

    linux格式化磁盘 查看系统磁盘情况 [root@db02 ~]# fdisk -l #查看当前系统上所有存储设备(包括挂在和没挂载的)  注:如果没有管理员权限是看不见磁盘的,因为fdisk默认读 ...

  3. List<VO>转成List<Map>

    List<A01090021BatchAddCheckVO> list = (ArrayList<A01090021BatchAddCheckVO>) result.get(& ...

  4. HTML_标签

    <!--HTML:1.概念:最基础的网页开发语言Hyper Text Markup Language 超文本标记语言超文本:超文本是用超链接的方法,将各种不同空间的文字信息组织在一起的网状文本. ...

  5. springmvc常用知识总结,不定期更新

    1.@Controller 注解到类名上,表示该类是控制器. 2.@RequestMapping("/xxxx") 可以放在类名/方法名之上,表示访问请求该方法时的映射url.如果 ...

  6. windows2012 日志查看过程

    Windows2012界面修改好造成有些人不知道在哪里查找windows 日志 我这边截图描述一下 1. 2.输入 命令  eventvwr.msc 3.弹出 windows 事件查看器 4.若需要  ...

  7. phonegap 开发指南系列(3) ----在Eclipse中Android开发环境搭建

      前提条件:已在Eclipse中安装好Android SDK 和 ADT. 1.下载PhoneGap,解压. 2.用Eclipse新建一个安卓项目. 3.将phoneGap解压包里的Android文 ...

  8. 期望dp+高斯消元+bfs——hdu4418

    高斯消元又弄了半天.. 注意只要能建立矩阵,那就必定有解,所以高斯消元里可以直接return 1 #include<bits/stdc++.h> using namespace std; ...

  9. jenkins实现不同角色查看不同视图

    1.安装插件Role-based Authorization Strategy 2.开启插件 系统管理>>>全局安全配置 3.创建角色和用户 4.登陆查看,只能看到travel开头的 ...

  10. flutter中的BuildContext

    https://www.jianshu.com/p/509b77b26b78