pat1085. Perfect Sequence (25)
1085. Perfect Sequence (25)
時間限制 300 ms 內(nèi)存限制 65536 kB 代碼長度限制 16000 B 判題程序 Standard 作者 CAO, PengGiven a sequence of positive integers and another positive integer p. The sequence is said to be 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 are supposed to find from the sequence as many numbers as possible to form a perfect subsequence.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (<= 105) is the number of integers in the sequence, and p (<= 109) is the parameter. In the second line there are N positive integers, each is no greater than 109.
Output Specification:
For each test case, print in one line the maximum number of integers that 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提交代碼
?
1 #include<cstdio> 2 #include<stack> 3 #include<algorithm> 4 #include<iostream> 5 #include<stack> 6 #include<set> 7 #include<map> 8 #include<vector> 9 using namespace std; 10 long long line[100005]; 11 int main(){ 12 //freopen("D:\\INPUT.txt","r",stdin); 13 long long n,p; 14 scanf("%lld %lld",&n,&p); 15 int i,j; 16 for(i=0;i<n;i++){ 17 scanf("%lld",&line[i]); 18 } 19 sort(line,line+n); 20 int amount; 21 long long cur=line[0]*p; 22 for(j=0;j<n&&line[j]<=cur;j++);//j指針 23 amount=j; 24 for(i=1;i<n&&j<n;i++){//這里的j<n是為了避免不必要的循環(huán) 25 cur=line[i]*p; 26 for(;j<n&&line[j]<=cur;j++); 27 if(j-i>amount){ 28 amount=j-i; 29 } 30 } 31 printf("%d\n",amount); 32 return 0; 33 }?
轉(zhuǎn)載于:https://www.cnblogs.com/Deribs4/p/4784082.html
總結(jié)
以上是生活随笔為你收集整理的pat1085. Perfect Sequence (25)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 令人苦恼的调试缓慢问题
- 下一篇: JavaScript中的继承