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& ... 
随机推荐
- Jmeter压测快速体验
			前言 最近在看neo4j相关的官网文档以及一些调优参数,同时也学了下Jmeter,为了测试下neo4j服务的性能,虽然不是专业搞测试的,但是我觉得每个优秀的开发者都应该学会主动压测自己服务和代码的性能 ... 
- Activiti学习笔记5 — 常用API解析
			常用API解析: 一.ProcessEngineConfiguration 流程引擎配置对象(配置数据库连接4个大配置和建表策略) 二.ProcessEngine 流程引擎核心对象( ... 
- 机器突然宕机导致hdfs启动一直超时的行为
			今天手里其中一个集群几个机器突然宕机,启动hdfs一直超时. clouder-scm-agent主要报了这个错RROR: Unexpected error 'getpwuid(): uid not f ... 
- FTP、SFTP、SCP、SSH、OpenSSH关系解密
			FTP(File Transfer Protocol):是TCP/IP网络上两台计算机传送文件的协议,FTP是在TCP/IP网络和INTERNET上最早使用的协议之一,它属于网络协议组的应用层.FTP ... 
- Yii2 中使用ts
			在运行环境 vagrant Ubuntu box 中安装 sass ,typescript等 安装需要的软件: sudo su -c "gem install sass" # 可选 ... 
- bzoj1568 Blue Mary
			题意:P:加入一条一次函数.Q:询问x位置的最大函数值. 标程: #include<bits/stdc++.h> using namespace std; ; int q,x,n; dou ... 
- 关于Cadence OrCad 16.6的破解
			相信很多人都知道去老吴的博客上找安装包和破解文件,但是上面的自称一键式破解程序.以及破解图文说明,都是很有问题的. 首先,该一键式破解程序默认的文件后缀与该程序指向的安装压缩包后缀不一致:其次,该程序 ... 
- JavaScript - 常用对象相关
			1. String对象 length : 字符串的长度 charAt(index) : 返回指定位置的字符串, 下标从0开始 indexOf(str) : 返回指定的字符串在当前字符串中首次出现的位置 ... 
- Open CV 环境配置
			{ //https://github.com/zhmmmm/ANYTOOL-2.0.0.0.2Version/tree/master/OpenCVProject } /* //各个版本下载 https ... 
- linux watch命令查看网卡流量
			watch命令可以反复的执行一个命令,默认时间间隔为2秒钟.TX是发送(transport),RX是接收(receive)RX bytes:总下行流量TX bytes:总上行流量 可以每隔两秒监视网络 ... 
