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

Source: Internet
Author: User

Pat1085 CodeTitle Description:

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 a positive integers n and p, where N (<= 5) is the number ofintegers in The sequence, and P (<=9) is the parameter. The second line there was N positive integers, each of which is no greater than9.

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 82 3 20 4 5 1 6 7 8 9
Sample Output:
8

AC Code:
#include <cstdio> #include <cstdlib> #include <algorithm> #define MAXN 100005using namespace std; Double v[maxn];int main (int Argc,char *argv[]) {int n;double p;int i,j;scanf ("%d%lf", &n,&p); for (int i=0;i<n; i++) scanf ("%lf", &v[i]); sort (v,v+n); int maxlen=0;for (i=0;i<n;i++) {for (j=i+maxlen-1;j<n;j++) {Double Temp =v[i]*p;if (v[j]>temp) break;if (maxlen<j-i+1) maxlen=j-i+1;} printf ("%d\n", MaxLen);}

Doubts: The topic clearly said n,p and array elements are positive integers, why only a double after the last case to pass, the test data and the title description does not match???

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

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.