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)