本次采用two points的写法
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=100001;
int main()
{
int n,a[maxn];
LL m;
cin>>n>>m;
for (int i=0;i<n;i++)
scanf("%d",&a[i]);
LL temp;
sort(a,a+n);
int i=0,j=0,count =0;
while (i<n&&j<n)
{
temp=a[i]*m;
while (j<n&&temp>=a[j])
j++;
count =max(count,j-i);
i++;
}
printf("%d",count);
}
本文介绍了一种使用双指针技巧解决C++算法竞赛中特定类型问题的方法。通过示例代码展示了如何利用双指针遍历数组,寻找满足特定条件的元素组合,以优化算法效率。

被折叠的 条评论
为什么被折叠?



