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

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

题目大意:给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入第一行给出两个正整数N(输入正数的个数)和p(给定的参数),第二行给出N个正整数。在一行中输出最多可以选择多少个数可以用它们组成一个完美数列

分析:简单题。首先将数列从小到大排序,设当前结果为result = 0,当前最长长度为temp = 0;从i = 0~n,j从i + result到n,【因为是为了找最大的result,所以下一次j只要从i的result个后面开始找就行了】每次计算temp若大于result则更新result,最后输出result的值~

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {int n;long long p;scanf("%d%lld", &n, &p);vector<int> v(n);for (int i = 0; i < n; i++)cin >> v[i];sort(v.begin(), v.end());int result = 0, temp = 0;for (int i = 0; i < n; i++) {for (int j = i + result; j < n; j++) {if (v[j] <= v[i] * p) {temp = j - i + 1;if (temp > result)result = temp;} else {break;}}}cout << result;return 0;
}

1085. Perfect Sequence (25)-PAT甲级真题相关推荐

  1. 1078. Hashing (25)-PAT甲级真题

    1078. Hashing (25) The task of this problem is simple: insert a sequence of distinct positive intege ...

  2. 1020. Tree Traversals (25) PAT甲级真题

    之前我看了这道题,实在是看不懂网上的解题答案,他们的具体思路基本上就是通过后续遍历和中序遍历,直接推出层次遍历. 我苦思冥想了半天,是在没看懂这种思路,于是想了一个笨点的但是也比较好理解的思路,通过后 ...

  3. 1040. Longest Symmetric String (25)-PAT甲级真题

    Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...

  4. 1006. Sign In and Sign Out (25)-PAT甲级真题

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  5. 1007. Maximum Subsequence Sum (25)-PAT甲级真题(最大连续子序列和、动态规划dp)

    Given a sequence of K integers { N1, N2, -, NK }. A continuous subsequence is defined to be { Ni, Ni ...

  6. 1121. Damn Single (25)-PAT甲级真题

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  7. 1090. Highest Price in Supply Chain (25)-PAT甲级真题

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  8. 1106. Lowest Price in Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. 1114. Family Property (25)-PAT甲级真题(并查集)

    This time, you are supposed to help us collect the data for family-owned property. Given each person ...

最新文章

  1. Umbra 3:次世代的遮挡裁剪
  2. [转]Oracle 服务器名配置
  3. springboot热部署工具
  4. P1420 最长连号(python3实现)
  5. 嵌入式linux设备驱动程序是,嵌入式Linux设备驱动开发之:按键驱动程序实例-嵌入式系统-与非网...
  6. MPLS ××× Carrier Supporting Carrier Option AB(二)
  7. SQL2000系统表、存储过程、函数的功能介绍及应用
  8. 同样学软件测试,为什么有些人一面试就拿一堆大厂offer?
  9. Android图形之HWC(二十四)
  10. 二进制算法——模二运算
  11. QQ空间批量删除留言
  12. 【微信JSSDK】PHP版微信录音文件下载
  13. 全国超能吃辣的省份,连四川和湖南都不是对手
  14. JS黄金分割法实现随机漂亮颜色!
  15. 英语兔音标学习之双元音
  16. 服务器故障英文邮件,全球邮
  17. 打开网络邻居有很多计算机,教你网上邻居无法看到其它共享电脑的解决方法
  18. R包estimate评估肿瘤组织中基质及免疫细胞浸润水平
  19. iOS_隐藏系统音量(MPVolumeView初探)
  20. 高校课堂机器人工程方向教学设计不足与工作反思

热门文章

  1. 与中石油分享SOA成功实践
  2. Node.js 指南(入门指南)
  3. linux C/C++内存检测
  4. HTML中的padding和margin
  5. 入职五年回顾(十五) 2013年10月
  6. Jquery实现可拖拽的树菜单
  7. oracle 创建字段自增长——两种实现方式汇总(转)
  8. Arm 架构下的中断
  9. SqlConnection,SqlCommand,SqldataReader的用法总结
  10. Windows PsExec 0day 漏洞获免费微补丁,但仅适用于最新版本