首页
学习
活动
专区
圈层
工具
发布
30 篇文章
1
PAT (Basic Level) Practice (中文)1054 求平均值 (20 分)
2
PAT (Basic Level) Practice (中文)1051 复数乘法 (15 分)
3
PAT (Basic Level) Practice (中文)1050 螺旋矩阵 (25 分)
4
PAT (Basic Level) Practice (中文)1046 划拳 (15 分)
5
PAT (Basic Level) Practice (中文)1045 快速排序 (25 分)
6
PAT (Basic Level) Practice (中文)1047 编程团体赛 (20 分)
7
PAT (Basic Level) Practice (中文)1043 输出PATest (20 分)
8
PAT (Basic Level) Practice (中文)1042 字符统计 (20 分)
9
PAT (Basic Level) Practice (中文)1040 有几个PAT (25 分)
10
PAT (Basic Level) Practice (中文)1038 统计同成绩学生 (20 分)
11
PAT (Basic Level) Practice (中文)1036 跟奥巴马一起编程 (15 分)
12
PAT (Basic Level) Practice (中文)1034 有理数四则运算 (20 分)
13
PAT (Basic Level) Practice (中文)1032 挖掘机技术哪家强 (20 分)
14
PAT (Basic Level) Practice (中文)1031 查验身份证 (15 分)
15
PAT (Basic Level) Practice (中文)1030 完美数列 (25 分)
16
PAT (Basic Level) Practice (中文)1029 旧键盘 (20 分)
17
PAT (Basic Level) Practice (中文)1028 人口普查 (20 分)
18
PAT (Basic Level) Practice (中文)1027 打印沙漏 (20 分)
19
PAT (Basic Level) Practice (中文)1025 反转链表 (25 分)
20
PAT (Basic Level) Practice (中文)1053 住房空置率 (20 分)
21
PAT (Basic Level) Practice (中文)1024 科学计数法 (20 分)
22
PAT (Basic Level) Practice (中文)1022 D进制的A+B (20 分)
23
PAT (Basic Level) Practice (中文)1049 数列的片段和 (20 分)
24
PAT (Basic Level) Practice (中文)1021 个位数统计 (15 分)
25
PAT (Basic Level) Practice (中文)1048 数字加密 (20 分)
26
PAT (Basic Level) Practice (中文)1019 数字黑洞 (20 分)
27
PAT (Basic Level) Practice (中文)1017 A除以B (20 分)
28
PAT (Basic Level) Practice (中文)1016 部分A+B (15 分)
29
PAT (Basic Level) Practice (中文)1015 德才论 (25 分)
30
PAT (Basic Level) Practice (中文)1014 福尔摩斯的约会 (20 分)

PAT (Basic Level) Practice (中文)1030 完美数列 (25 分)

1030 完美数列 (25 分)

给定一个正整数数列,和正整数 p,设这个数列中的最大值是 M,最小值是 m,如果 M≤mp,则称这个数列是完美数列。

现在给定参数 p 和一些正整数,请你从中选择尽可能多的数构成一个完美数列。

输入格式:

输入第一行给出两个正整数 N 和 p,其中 N(≤10​5​​)是输入的正整数的个数,p(≤10​9​​)是给定的参数。第二行给出 N 个正整数,每个数不超过 10​9​​。

输出格式:

在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。

输入样例:

代码语言:javascript
复制
10 8
2 3 20 4 5 1 6 7 8 9

输出样例:

代码语言:javascript
复制
8

首先,先排序,线性遍历一遍,扫到a[i]时,upperbound找出第一个比 k*a[i]大的数a[p],那么对于a[i]这个元素而言,p-1就是满足完美数列且元素数最多的最大值的那个下标,不断与最大值比较即可~

代码语言:javascript
复制
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
set<ll>t;
ll n,k,a[maxn];
int main()
{
    cin>>n>>k;
    for(rg i=1;i<=n;i++)
    {
        a[i]=read();
    }
    sort(a+1,a+1+n);
    ll maxx=-inf;
    for(rg i=1;i<=n;i++)
    {
        //cout<<upper_bound(a+1,a+1+n,a[i]*k)-a-1<<endl;
        maxx=max(maxx,upper_bound(a+1,a+1+n,a[i]*k)-a-i);
    }
    cout<<maxx<<endl;
   	return 0;
}
下一篇
举报
领券