1085. Perfect Sequence
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
知识点:
剪枝,遍历的时候,如果 list[i]*p < list[j] 的话,就剪枝
另外,比当前完美序列长度小的就不用遍历了,j 直接从 i+cnt 开始
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; int main(){
vector<int> list;
long long p,tmp;
int n; scanf("%d %lld",&n,&p); for(int i=;i<n;i++){
scanf("%lld",&tmp);
list.push_back(tmp);
}
sort(list.begin(),list.end()); int cnt=; for(int i=;i<n;i++){
for(int j=i+cnt;j<n;j++){
if(list[i]*p>=list[j]){
if(j-i>cnt)
cnt=j-i;
}else{
break;
}
}
}
printf("%d",cnt+);
}
1085. Perfect Sequence的更多相关文章
- 1085 Perfect Sequence (25 分)
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- 1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
- 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 ...
- 1085. Perfect Sequence (25)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...
- PAT (Advanced Level) 1085. Perfect Sequence (25)
可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...
随机推荐
- Linux移植之make uImage编译过程分析
编译出uboot可以运行的linux内核代码的命令是make uImage,下面详细介绍下生成linux-2.6.22.6/arch/arm/boot/uImage的过程: 1.vmlinux.Ima ...
- Linux pip安装使用详解
简介 pip是Python有它自己的包管理工具,与yum和apt-get相似. 安装步骤: 1.下载get-pip.py:https://bootstrap.pypa.io/get-pip.py 2. ...
- js分割数字
var str = "123"; var b = String(str).split(''); 打印b[0].b[1].b[2]看效果...
- Jenkins+svn+maven自动部署到tomcat
jenkins所在主机配置好,jdk,maven,Tomcat 1.配置maven,jdk环境 1) 进入配置界面--->[系统管理]--->[Global Tool Configurat ...
- C++中的set
总结一下: vector:封装了数组 list:封装了列表 map,set:封装了二叉树 set:用来存储同一类型的数据类型 非关联容器相对关联型容器插入效率高,原因是:不需要内存拷贝和内存移动, ...
- (转)在JAVA实现DataTable对象(三)——DataTable对象实现
大家都是行家,我就直接上代码了,我这个代码应该还是能看懂的,嘻嘻…. 1: import java.util.ArrayList; 2: import java.util.List; 3: 6: ...
- PAT 1016 部分A+B(15)(C++&JAVA&&Python)
1016 部分A+B(15 分) 正整数 A 的"DA(为 1 位整数)部分"定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 A=3862767,D ...
- nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator
该问题是少了一个spring-tx-的jar包,把该包加入到buildpath中就行了. 参考链接:http://blog.csdn.net/Rongbo_J/article/details/4666 ...
- ps教程分享:一定要记住这20种PS技术!
一定要记住这20种PS技术!会让你的照片美的不行! 一种简单的数码照片后期润饰 1)打开图片,执行色像/饱和度(-40)降低饱和度. 2)新建一图层,将图层模式改为柔光,用画笔工具将需要润饰的部分画几 ...
- MD5加密及Hash长度拓展攻击【通俗易懂】
先放一个简单点的利用了Hash长度拓展攻击的题目 if($COOKIE["getmein"] === md5($secret . urldecode($username . $pa ...