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
作者: CAO, Peng
单位: 浙江大学
时间限制: 200 ms
内存限制: 64 MB
代码长度限制: 16 KB
具体代码
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){int n,p;scanf("%d%d",&n,&p);int a[100010];for(int i=0;i<n;i++){scanf("%d",&a[i]);}sort(a,a+n);int ans=0;for(int i=0;i<n;i++){int j=upper_bound(a,a+n,(long long)a[i]*p)-a;ans=max(ans,j-i);//之所以有用for循环是防止极端情况123,m和p为3。}printf("%d",ans);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 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整 ...
最新文章
- Redis 命令--Redis集合(Set)
- 日志处理两大生态Splunk和ELK深度对比
- 《可穿戴创意设计:技术与时尚的融合》一一3.3 纺织与教育
- 如何开发Teams Bot
- HTTP方法:幂等性和安全性
- 关于c++中运算符的总结
- 【CSS】利用宽高比例的媒体查询
- async与await详解
- Dell服务器通过IDRAC9收集TSR日志排查故障
- 列表查询数据交互简写形式
- linux 命令 — cut
- 公募FOF同质化产品情况引人关注
- django xadmin 安装和使用
- 「JXOI2018」游戏
- 网页版模仿Excel
- 佳顺通用进销存系统去广告_免费在线进销存软件弊端之重复投资
- jquery点击事件写法
- 【C语言经典100例】-- 11 不死神兔问题
- dialog沉浸式状态栏android,Dialog全屏,去掉状态栏的方式
- 应急响应-linux-webshell查查杀工具:河马webshell查杀和深信服Webshell
热门文章
- AC日记——【模板】二分图匹配 洛谷 P3386
- 微软Windows系统命令和Sysinternals系列工具
- Oracle Active database duplication
- linux mkdir基础命令总结
- 包导出Android升级ADT22后会报ClassNotFoundException的原因分析
- WF4.0 RC 对比 Beta2 的变化
- unity透明物体显示问题
- avue 文字点击 弹窗_目前最好用的文字转语音、视频配音方法,一键合成,智能黑科技...
- 超效率dea matlab,MATLAB在超效率DEA模型中的应用
- sxssfworkbook 设置单元格大小_Offset属性和Resize属性相结合,完美实现选择区域大小的改变...