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& ...
随机推荐
- ES6 学习 -- Class继承
(1)如何继承Class可以通过extends关键字实现继承,如下:class Father { } class Child extends Father { }// 这里子类Child继承父类Fat ...
- pytorch clamp 与clamp_区别
pytorch clamp 与clamp_ ,有下划线的表示修改并付给自身,无下划线的表示需要返回处理后的值,比如: h = k.clamp(min=0) #将结果存入h,k保留原值 k.clamp_ ...
- css3 动画属性
transition Internet Explorer 9 以及更早版本的浏览器不支持 transition 属性. Internet Explorer 10.Firefox.Opera 和 Chr ...
- Git的配置及克隆项目到本地
- js数组方法 slice()和splice()
说实在我之前都不怎么分的清这个两个函数,因为这两个函数名字那么像,经常我就弄混了,平常使用的时候都先查一下我需要使用的实际是哪个函数.这样不说很浪费时间,但是也是影响了开发效率,所以我决定今天就彻底区 ...
- APB简介
一.血缘 AMBA: Advanced Microcontroller Bus Architecture 高级处理器总线架构 AHB: Advanced High-performance Bus 高级 ...
- dos中文显示乱码怎么办?
其实只需要一条命令 chcp 65001 执行该操作后,代码页就被变成UTF-8了 也可是GBK, 命令式: chcp 936 2.修改窗口属性,改变字体 在命令行标题栏上点击右键,选择&quo ...
- 概率dp——cf148D
求概率应该dp数组应该顺着求 这是由初始状态来决定递推方向的 /* 盒子里有两种颜色的球,一种是黑色另一种是白色 AB轮流去球,A先取 A每次随机摸一个球 B每次随机摸一个球,然后盒子里再丢一个球 先 ...
- BZOJ 1010 (HNOI 2008) 玩具装箱
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MB Submit: 12665 Solved: 5540 [Submit][S ...
- 命令学习_nslookup
nslookup 域名 这是最常用最简单的用法,可以直接获得目标域名的IP地址和CNAME. 如下是A记录的返回情况 nslookup命令会采用先反向解释获得使用的DNS服务器的名称,上图中ns.gu ...