PAT甲级——A1085 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 (≤) 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 ;
}
最新文章
- [ACM_动态规划] ZOJ 1425 Crossed Matchings(交叉最大匹配 动态规划)
- [python]逆水行舟不进则退(1)
- CGOS461 [网络流24题] 餐巾(最小费用最大流)
- yii2封装一个类控制div宽度,高度
- Tar命令用法详解
- 使用QEMU调试Linux内核代码
- 内存数据库MemSQL ——基于内存,MVCC+哈希表、跳表
- All About JAVA Maven的安装
- Objective-c 中的算术函数和常数的表示
- nginx的内页跳转总结
- jmeter JDBC请求连接测试mysql数据库
- linux shell 推断文件或目录是否真的存在
- Ubuntu 14.04 鼠标消失解决方案
- char在C语言一个字节表示的数据范围
- -1-2 java 面向对象基本概念 封装继承多态 变量 this super static 静态变量 匿名对象 值传递 初始化过程 代码块 final关键字 抽象类 接口 区别 多态 包 访问权限 内部类 匿名内部类 == 与 equal
- MySql 主从复制 mysql-proxy实现读写分离
- 使用 PySide2 开发 Maya 插件系列三:qt语言国际化(internationalization)
- php-beanstalkd消息队列类分享
- DDD简明入门之道 - 开篇
- 去除inline-block出现间距的几种方法
热门文章
- 5个CSS3技术实现设计增强
- iOS开发系列-iOS布局相关
- vba取局域网电脑共享文件夹下的Excel文件
- PHP出现报警后需要修改 date.timezone 的值(php.ini)
- sleep()与wait()的区别
- Android开发 View_自定义圆环进度条View
- CSIC_716_20191107【深拷贝、文件的编码解码、文件的打开模式】
- Windows ping
- 0704 Process继承实现多进程、Pool进程池,进程间通过队列通信,Pool实现多进程实现复制文件
- django-filter 实现过滤时查询是否包含在数组的方法,in数组的实现