1085 Perfect Sequence (25 point(s))

【信息科学与工程学】【通信工程】第一百九十一篇 路由器体系结构03 编号类型领域问题详细的数学分析(逐步推理)参数列表(表达式 / 数值范围 / 边界 / 测量)关联知识839DCI演进 · 收敛DCI 2030 年三大技术收敛方向步骤1:方向一:IPoDWDM 成为绝对主流(Omdia 2027 59% → 2030 80%+),OTN 退化为 OLS 纯光层。步骤2:方向二:800ZR+ 取代 400ZR 成为主力速率,PCS 使 800G 达 600–1000km。步骤3:方向三:AI 集群 DCI 催生 1.6T/3.2T 超短距(<10km)相干模块(OSFP-X 阅读详情

1085 Perfect Sequence (25 point(s))

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(≤10​5​​) is the number of integers in the sequence, and p (≤10​9​​) is the parameter. In the second line there are Npositive integers, each is no greater than 10​9​​.

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

思路见代码,很容易懂!思路参考大神:https://blog.youkuaiyun.com/richenyunqi/article/details/79512471

复杂度是o(n^2):case#4出现TLE(22分)

#include<iostream>
#define ll long long
using namespace std;
const int N  = 1e5+7;
int a[N];
int main(void){
	int n;ll p;
	cin>>n>>p;
	for(int i=0;i<n;i++) cin>>a[i];
	int cnt = 0;int ans = 0;
	for(int i=0;i<n;i++){
		ll m = a[i];cnt=0;
		for(int j=0;j<n;j++){
			ll M = a[j];
			if(M<=p*m&&M>=m) cnt++;
		}
		if(cnt>ans) ans=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

看起来复杂度没有变,需要在之后的序列中去查找第一个大于其p倍的数,实际上STL使用二分查找解决,降低复杂度。

#include<iostream>
#include<algorithm> 
#define ll long long
using namespace std;
const int N  = 1e5+7;
ll a[N];
int main(void){
	int n;ll p;
	cin>>n>>p;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	int maxLen = 0;
	for(int i=0;i<n;i++){
		int len = upper_bound(a+i+1,a+n,a[i]*p)-a-i;//二分查找降低复杂度 
		maxLen = max(len,maxLen);
	}
	cout<<maxLen<<endl;
	return 0; 
}

双指针(非常巧妙,仔细想也容易想到):

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long p;
    scanf("%d%lld",&N,&p);
    long long a[N];
    for(int i=0;i<N;++i)
        scanf("%lld",&a[i]);
    sort(a,a+N);
    int i=0,j=0,maxLength=-1;
    while(j!=N){
        while(j!=N&&a[i]*p>=a[j])
            ++j;
        maxLength=max(maxLength,j-i);
        ++i;
    }
    printf("%d",maxLength);
    return 0;
}

 

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇 编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不 阅读详情

相关推荐

工业场景落地:Java+PaddleOCR实现高性能OCR文字识别的终极方案

本文深度解析基于Java的高性能工业级OCR实现方案,集成PP-OCRv5深度学习模型,提供: ✅ 多场景支持:手写体、竖排文本、票据表格的精准识别 ✅ 工业级性能:毫秒级响应,支持GPU加速与高并发处理 ✅ 开箱即用:通过Maven快速集成,5行代码完成文字识别 ✅ 完整技术栈:覆盖文本检测、方向校正、识别后处理全流程 附可运行示例代码,助您快速构建企业级OCR系统!

deng775747758的博客 3612

[PAT-A 1085]Perfect Sequence

题目大意: 给定一个正整数数列和正整数p,设这个数列中最大值是M,最小值是m,如果M<m*p,则称这个数列是完美数列 给定参数p和一些正整数,从中选择尽可能多的数构成一个完美数列。求选择出的数的个数. 即从N个正整数中选择若干个数,使得选出的这些数中的最大值不超过最小值的p倍,问满足条件的选择方案中,选出的数的最大个数。 思路: 1)将数列从小到大排序。 2)从左至右扫描序列,对其中的每一...

RegulusF的博客 241

过压保护电路(OVP)

作者:AirCity 2020.2.4 Aircity007@sina.com 本文所有权归作者Aircity所有 1 示例一 当VBUS=5V时,各点电压电流如图所示,Q1接近截止,输出信号是5V。 当VBUS=5.4V开始,输出信号开始下降,直到VBUS=6.1V,输出信号降低为0.6V。 下面是实测波形,这个电路,输出信号的电压不会超过5.4V,这个输出信号可用于电源的控制信号。 2 ...

AirCity123的博客 3万+

PAT甲级-1085 Perfect Sequence

PAT甲级-1085 Perfect Sequence

weixin_74092648的博客 414

鱼眼相机去畸变(图像拉直/展开/矫正)算法及实战总结

1、算法说明经纬度矫正法, 可以把鱼眼图想象成半个地球, 然后将地球展开成地图,经纬度矫正法主要是利用几何原理, 对图像进行展开矫正。经过P点的入射光线没有透镜的话,本应交于相机成像平面的e点。然而,经过鱼眼相机的折射,光线会交于相机成像平面的d点,就产生了畸变,因此畸变图像整体上呈现出像素朝图像中心点聚集的态势。而去畸变,就是将折射到d点的点,重新映射回到e点,因此去畸变之后的图像与原始的鱼眼图像相比,仿佛是把向心聚集的像素又重新向四周铺展开来。AVM环视系统——鱼眼相机去畸变算法 - 知乎。

大胡子大叔的专栏 2万+

CESM笔记——CESM1.0-CESM1.2.2-CESM2.1.3三个版本模式工作流对比

最近测试了CESM1.0,CESM1.2.2和CESM2.1.3三个版本,不同版本在workflow上有一些区别,来做点笔记。 CESM1.0 测试compset:B_2000,F_2000 workflow: 1. create_newcase -case ~/CESM/cesm1_0/script/B_2000 -compset B_2000 -res f19_g16 -mach tianhe 2. cd B_2000 (optional) env_mach_pes.xml ##修改核数,

砍柴姑娘Jourosy的博客 4944

『1085』Perfect Sequence

Given a sequence of positive integers and another positive integerp. The sequence is said to be aperfect sequenceifM≤m×pwhereMandmare the maximum and minimum numbers in the sequence,...

weixin_52435933的博客 191

Flightmare实战:从零搭建强化学习无人机控制环境

本文详细介绍了从零开始搭建Flightmare强化学习无人机控制环境的完整流程。内容包括环境准备、核心库安装、依赖冲突解决,以及如何运行PPO算法示例进行训练与可视化测试。文章还提供了环境配置、自定义任务修改及常见问题的避坑指南,帮助开发者快速上手这一模块化的无人机RL仿真平台。

weixin_29081101的博客 356

【PAT甲级 - C++题解】1085 Perfect Sequence

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 768

手把手教你用Simulink给C2000配置SCI串口发送数据(附模型与避坑点)

本文详细介绍了如何使用Simulink为C2000系列微控制器配置SCI串口发送数据,包括硬件资源分配、模型搭建、参数设置及调试技巧。通过代码生成和串口通信实践,帮助开发者高效实现嵌入式系统开发,避免常见通信问题。

weixin_30831529的博客 295

Dify框架面试内容整理-如何优化Dify的应用性能?

为1536维)可选用 PCA、FAISS 的量化压缩方法降低维度(如128、256、512);对知识库预览、任务流配置等页面,使用 nginx/cache-control 减少请求。API 响应耗时(P50/P95)、Token 使用量、缓存命中率、向量检索耗时;对 Prompt+输入内容计算 Hash,缓存相同请求的返回结果;使用占位符 + 函数拼接,按需组合 Prompt,而非静态长模板;数据量大时,应在构建索引前清洗冗余段落、统一格式,避免重复向量。维度越低,检索越快,但可能影响召回准确度,需平衡。

不务正业的猿 1551

【PAT甲级】1085 Perfect Sequence(二分法)

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 Mand m are the maximum and minimum numbers in the sequence, respectiv...

Y_CanFly的小小博客 333

太空安全卫士:基于YOLOv5的空间态势感知系统(实现轨道碰撞预警与太空环境保护)

做完这个项目,你会发现自己完整走过了“数据采集→标注→模型训练→功能集成→界面开发”的毕设全流程,这不仅是技术能力的证明,更是对“技术守护宇宙安全”这一理念的实践。答辩时,你可以重点讲这几点:系统解决了航天监测的哪些痛点、YOLOv5在太空目标检测中的性能优势、系统未来能怎么优化(比如对接航天监测网络、实现实时轨道预测)。未来,这个系统还能往“更智能”的方向发展:比如结合轨道计算预测碰撞风险、开发移动端APP让天文爱好者参与太空垃圾上报、在航天任务中实现全自动避障决策……想象空间很大。

m0_71589036的博客 90

1085 Perfect Sequence (25point(s))

1085 Perfect Sequence (25point(s)) 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 seq

佳迪斯的博客 120

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

1085 Perfect Sequence (25 point(s))

#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;vector&gt; #include&lt;algorithm&gt; using namespace std; typedef long long ll; vector&lt;ll&gt; res; int main() { int n; ll p; scanf(...

徐伯莱 244

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

1085 Perfect Sequence (25point(s)) - C语言 PAT 甲级

* 先快速排序原数列,从最小值遍历寻找最大的完美数列 * 题意 m 和 M 是对于完美数列的,这样 m 不同, M 也会变化,才有不同长度的完美数列 最初以为找到原始数列的最小值,并以此判断 M 来寻找完美数列(卒~)

有三只土豆 238

PAT_甲级_1085 Perfect Sequence (25point(s)) (C++)【双指针法】

目录 1,题目描述 题目大意 输入 2,思路 双指针法: 3,AC代码 4,解题过程 第一搏 第二搏 第三搏 第四搏 第五搏 1,题目描述 Sample Input: 10 8 2 3 20 4 5 1 6 7 8 9 Sample Output: 8 题目大意 从给定的一个序列中,找出一个序列,此序列的最大值M与最小值m满足:M≤m*p;...

&再见萤火虫&的博客 256

A 1085 Perfect Sequence (25 point(s)) __二分法&&two_pointers

题目要求: 给定p和数组 num [n],寻找数组中的一个子集,使该子集中的最小值m*p >= 子集中的最大值M,要求寻找子集的最大长度 思路: 先排序,然后从小到大枚举每一个元素,寻找符合题目条件的子集,并记录子集的最大值。 这种查找用二分法比较方便,可以自己写,当然也可以用upper_bound,时间复杂度在O(logn) //10 8 //2 3 20 4 5 1 6 7 8 ...

a7701935的博客 212

PAT甲级 1085 Perfect Sequence (25 分)

1085 Perfect Sequence (25 分) 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 num...

kelseyscat的博客 259

PAT甲级--1085 Perfect Sequence(25 分)【@水题】

1085 Perfect Sequence(25 分) 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 numb...

Imagirl1的博客 774

1085 Perfect Sequence

1085 Perfect Sequence 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 p

weixin_44230791的博客 317

PAT甲级1085 Perfect Sequence :[C++题解]双指针

刷题

阿正的梦工坊 510

1085 Perfect Sequence——PAT甲级(双指针)

大致思路是,先把给定的数组进行一遍排序,然后使用双指针i,j,分别指向左端(最小)和右端(最大),然后当mp>=M时,j不断右移直到不满足,此刻如果j没移到数组最右端,则记录当前最大值,并将i右移一位,否则标志已经获得最大数列长度,之后只能将i右移也就是缩短,无意义,结束循环。

flyidj的博客 637

PAT甲级1085(完美数列)

1085 Perfect Sequence (25 point(s))   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 min...

云胡的博客 478

Perfect Sequence

1085 Perfect Sequence原题链接解题思路源代码 原题链接 PAT 甲级 1085 Perfect Sequence 解题思路 给定一个数p,如果一个序列满足,M≤m×p,则是完美数列,m和M分别是序列中的最大值和最小值。 显然,首先对序列进行排序,完美序列一定是该序列的一个连续子序列。 排好序后,从小到大枚举每个元素(不一定从首元素开始的是最长的),假定完美序列从该元素开始,此...

qq_40486952的博客 591
上一篇: 1080 Graduate Admission
下一篇: 1050 String Subtraction (20 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值