Links: Http://www.nowcoder.com/questionTerminal/5bed191944ce4eaa93f4bae50abc90df
Title Description
Given a positive integer sequence, and a positive integer p, the maximum value in this sequence is m, the minimum is m, and if M <= m * p, then this sequence is called the perfect sequence.
Now given the parameter p and some positive integers, you can choose as many numbers as possible to make a perfect sequence.
Input Description:
Enter the first line to give two positive integers n and p, where N (<= 105) is the number of positive integers entered, and P (<= 109) is the given parameter. The second line gives n positive integers, each of which
No more than 109.
Output Description:
You can select the maximum number of rows in a row to make a perfect sequence.
Input Example:
10 8
2 3 20 4 5 1 6 7 8 9
Output Example:
8
Train of thought: test instructions is very simple, but really need to consider the efficiency of the words also needs to think of ways. AC code is looked at others, the idea is very good, earnest study!
1 AC Code:2#include"iostream"3#include <cstdio>4#include <string.h>5#include <string>6#include <cmath>7#include <algorithm>8 using namespacestd;9 Ten Const intMAXN =100005; One intNUM[MAXN]; A - - intMain () the { - intN, p, I, J; -scanf"%d%d", &n, &p); - for(i=1; i<=n; ++i) + { -scanf"%d", &num[i]); + } ASort (num+1, num+n+1); at intlen=0, flag=0; - for(intI=1; i<=n; ++i) - { - for(intJ=i+len; j<=n; ++j) - { - if(Num[j] > num[i]*p) in { - Break; to } + if(j-i+1>len) - { theLen = j-i+1; * } $ }Panax Notoginseng } -cout <<len <<Endl; the return 0; +}
1 tle Code:2#include"iostream"3#include <iomanip>4#include <string.h>5#include <string>6#include <vector>7#include <cmath>8#include <cctype>9#include <algorithm>Ten using namespacestd; One A Const intMAXN =100005; - intNUM[MAXN]; - the intMain () - { - intN, p, I, J; - //cin >>n >>p; +scanf"%d%d", &n, &p); - for(i=1; i<=n; ++i) + { A //Cin >>num[i]; atscanf"%d", &num[i]); - } -Sort (num+1, num+n+1); - intlen=0, flag=0; - for(intI=n; i>=1; --i) - { in for(intj=1; j<=n-i+1; ++j) - { to if(num[j+i-1] <= p*Num[j]) + { -Len =i; theFlag =1; * Break; $ }Panax Notoginseng } - if(Flag = =1) the { + Break; A } the } +cout <<len <<Endl; - return 0; $}
Perfect series "pinned"