标签:col pointer cin 递增 ret 数列 stream while std
two pointers通向扫描法。
#include<iostream> #include<algorithm> using namespace std; typedef long long LL; LL a[100010] = {0}; int main() { int n,p,max = -1; cin>>n>>p; for(int i = 0; i < n; ++i) cin>>a[i]; sort(a,a+n);//递增排序 int i = 0,j = 0; while(i < n) {//two poniters同向扫描 while(j < n && a[j]<= a[i]*p)//用int型的话a[i]*p会溢出,所以数组定义成了long long类型 j++; if(max < j-i) max = j-i; i++; } cout<<max; return 0; }
标签:col pointer cin 递增 ret 数列 stream while std
原文地址:https://www.cnblogs.com/keep23456/p/12325589.html