1085. Perfect Sequence (25) "Two-point search"--pat (Advanced level) practise

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.