1085 Perfect Sequence(25 分)
1085 Perfect Sequence(25 分)
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
转载来自大佬:https://www.liuchuo.net/archives/1908
好吧,是我脑子犯浑了,怎么说,题目看不懂然后是 求>=maxn 我想成小于了难怪一直看不懂题解
代码:
#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 分)相关推荐
- 1085. Perfect Sequence (25)-PAT甲级真题
Given a sequence of positive integers and another positive integer p. The sequence is said to be a & ...
- pat 1085 Perfect Sequence (25) 二分查找
题意 给我们一个数串 让我们从中挑选数字 构成一个集合 使得集合中最小元素m和最大元素M 满足 m*p>=M 求出集合的最大数量 分析 看下条件就可以发现 m*p >=M 也就是在数串中找 ...
- pat1085. Perfect Sequence (25)
1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Give ...
- 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...
- PAT甲级1085 Perfect Sequence :[C++题解]双指针
文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:求满足条件M≤m×pM \leq m\times pM≤m×p的区间[m, M]最长是多少.此处有一性质:当最大值M变大的时候,最小值 ...
- 【PAT甲】1051 Pop Sequence (25分)判断出栈顺序的合法性
problem 1051 Pop Sequence (25分) Given a stack which can keep M numbers at most. Push N numbers in th ...
- 【详细注释】1051 Pop Sequence (25 分)
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a stack which can keep M numbers at most. Push N numbers in ...
- 1085 Perfect Sequence
明确题目的核心是要找到 找到第一个满足 M > m*p 的M的下标.然后用该下标减去起点的下标即为序列元素个数. 二分区间应当是M所有可能的取值范围.起点是i+1,终点是N而不是N-1,虽然A[ ...
- 【PAT甲级 stack queue的使用】1051 Pop Sequence (25 分) C++ 全部AC
题目 思路 维护三个集合:核心栈.数字队列.目标队列 详细思路见注释 题解 C++ #include<iostream> #include<stack> #include< ...
- 1085 PAT单位排行 (25分)-PAT乙级真题-C++实现
1085 PAT单位排行 (25分)-PAT乙级真题-C++实现 题目描述: 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整 ...
最新文章
- QIIME 2教程. 29参考数据库DataResources(2021.2)
- 阿里商业白皮书:每个企业都要变成一个数据公司
- shell查找符号链接及其指向目标的方法
- MyBatis中的大于、小于、like等符号写法
- 《构建之法》读后感5
- java 常量池详解
- pug模板引擎(原jade)
- android开机渲染视频太久,Android过度渲染优化解决方案
- vs 错误提示及解决方案
- 【APIO2015】Bali Sculptures
- JavaSE入门学习10:Java修饰符
- jquery操作复选框(checkbox)
- 频谱感知3:合作频谱检测中的硬合并与软合并
- 解决百度文库文字无法复制
- SXWIN7X64EN_20181104_NET_msu_LITE英文精简版
- 戴尔修复计算机软件,DELL电脑系统恢复工具(Dell OS Recovery Tool)2019 v2.3.6066官方版...
- 计算机协会活动策划,计算机协会活动策划书
- php时间转换位周月,php日周月统计代码
- Excise_Oop1
- android apk是什么文件,apk是什么文件?apk文件肿么打开?