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

又是没看清题,这道题的子序列不需要是原来的连续子序列,只要求是原来里面的值就行,搞得又浪费了很多时间!!!!
 1 //靠,不需要是子排序,就是找数字就行
 2 #include <iostream>
 3 #include <deque>
 4 #include <vector>
 5 #include <algorithm>
 6 using namespace std;
 7 int N;
 8 long long P;
 9 int main()
10 {
11     cin >> N >> P;
12     vector<int>num(N);
13     for (int i = 0; i < N; ++i)
14         cin >> num[i];
15     sort(num.begin(), num.end());
16     int res = 0;
17     for(int L=0,R=0;L<=R && R<N;++R)
18     {
19         while (L <= R && num[R] > P * num[L])
20             L++;
21         res = res > R - L + 1 ? res : R - L + 1;
22     }
23     cout << res << endl;
24     return 0;
25 }

原文地址:https://www.cnblogs.com/zzw1024/p/11337278.html

时间: 2024-10-10 16:12:40

PAT甲级——A1085 Perfect Sequence的相关文章

A1085. Perfect Sequence (25)

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 pa

PAT 甲级 1051 Pop Sequence

https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is

PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if

PAT 甲级 A1085 (2019/02/20)

#include<cstdio> #include<algorithm> using namespace std; const int MAXN = 100010; int n, p, a[MAXN]; int binarySearch(int i, long long x){ if(a[n - 1] <= x) //如果最大的数比x小,则返回n return n; int left = i + 1; int right = n - 1; //在区间[i+1, n-1]内查找

1085. Perfect Sequence (25)-PAT甲级真题

1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng 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

Pat(Advanced Level)Practice--1085(Perfect Sequence)

Pat1085代码 题目描述: 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 s

1085. Perfect Sequence (25)【二分查找】——PAT (Advanced Level) Practise

题目信息 1085. Perfect Sequence (25) 时间限制300 ms 内存限制65536 kB 代码长度限制16000 B 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 minim

pat 1085. Perfect Sequence (25)

时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng 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

PAT Perfect Sequence (25)

题目描述 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