Topic Information
1085. Perfect Sequence (+)
Time limit (MS)
Memory Limit 65536 KB
Code length limit 16000 B
Given a sequence of positive integers and another positive integer p. The sequence is said to being 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 is supposed to find from the sequence as many numbers as possible to form a P Erfect subsequence.
Input Specification:
Each input file contains the one test case. For each case, the first line contains the positive integers n and p, where N (<= 10^5) are the number of integers in th e sequence, and P (<= 10^9) is the parameter. The second line there was N positive integers, each of which is no greater than.
Output Specification:
For each test case, print in one line the maximum number of integers so 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
Thinking of solving problems
After sorting two points to find can
AC Code
#include <cstdio>#include <vector>#include <algorithm>using namespace STD;intMain () {Long LongN, p, t; vector<long long>Vscanf("%lld%lld", &n, &p); for(Long Longi =0; I < n; ++i) {scanf("%lld", &t); V.push_back (t); } sort (V.begin (), V.end ());intCNT =0; for(inti =0; I < v.size (); ++i) {t = p * V[i];intTMP = distance (V.begin (), Upper_bound (V.begin (), V.end (), T))-I; CNT = MAX (CNT, TMP); }printf("%d\n", CNT);return 0;}
1085. Perfect Sequence (25) "Two-point search"--pat (Advanced level) practise