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 ;
}
PAT甲级——A1085 Perfect Sequence的更多相关文章
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- A1085. Perfect Sequence
Given a sequence of positive integers and another positive integer p. The sequence is said to be a & ...
- 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 ...
- PAT 甲级 1051 Pop Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- PAT甲级——A1051 Pop Sequence
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...
- PAT甲级——1140.Look-and-say Sequence (20分)
Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...
- PAT_A1085#Perfect Sequence
Source: PAT A1085 Perfect Sequence (25 分) Description: Given a sequence of positive integers and ano ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
随机推荐
- centos7.3更换ssh默认登陆端口
说明:本方法目前通用于7.1-7.3 vim /etc/ssh/sshd_config 找到Port 22下面添加一行:Port 12345保存退出. systemctl restart sshd.s ...
- Go, JS和Websocket
JS中建立Websocket连接 var ws = new WebSocket("ws://hostname/path", ["protocol1", &quo ...
- Cut the Sequence
Cut the Sequence 有一个长度为n的序列\(\{a_i\}\),现在求将其划分成若干个区间,并保证每个区间的和不超过m的情况下,每个区间的最大值的和的最小值,\(0 < N ≤ 1 ...
- 常用Oracle操作语句
--常用的字段类型有:varchar2,char,nchar,date,long,number,float,BLOB,CLOB --添加表字段 ); --修改表字段 ); --删除表字段 alter ...
- hadoop新增新数据节点和退役数据节点
新增数据节点 0. 需求随着公司业务的增长,数据量越来越大,原有的数据节点的容量已经不能满足存储数据的需求,需要在原有集群基础上动态添加新的数据节点.1. 环境准备 (1)在hadoop03主机上再克 ...
- jquery学习笔记(五):AJAX
内容来自[汇智网]jquery学习课程 5.1 ajax AJAX 是与服务器交换数据的艺术,它在不重载全部页面的情况下,实现了对部分网页的更新. AJAX = 异步 JavaScript 和 XML ...
- 1636: Pascal山脉
1636: Pascal山脉 时间限制: 1 Sec 内存限制: 128 MB提交: 51 解决: 15[提交][状态][讨论版] 题目描述 小卡卡顺着老者所指的方向,来到了Pascal神峰的顶峰 ...
- JS 变量的数据类型转换
变量的类型转换,一般情况是JS自动转换的,但也有些时候需要手动转换. 1.其它类型转成布尔型 函数和方法的区别 Boolean(a) //函数是可以独立使用的 document.write(a) ...
- 026_JDBC
JDBC简介 JDBC(Java DataBase Connectivity,Java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编 ...
- Google Chrome浏览器安装xpath helper插件
1. 图中桌面的两个2.0.2_0文件就是xpath helper插件. --------------------------------------------------------------- ...