日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pat1085. Perfect Sequence (25)

發布時間:2025/7/25 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pat1085. Perfect Sequence (25) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1085. Perfect Sequence (25)

時間限制 300 ms 內存限制 65536 kB 代碼長度限制 16000 B 判題程序 Standard 作者 CAO, Peng

Given 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是為了避免不必要的循環 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 }

?

轉載于:https://www.cnblogs.com/Deribs4/p/4784082.html

總結

以上是生活随笔為你收集整理的pat1085. Perfect Sequence (25)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。