PAT_A1085#Perfect Sequence
Source:
Description:
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 (≤) is the number of integers in the sequence, and p (≤) is the parameter. In the second line there are N positive integers, each is no greater than 1.
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
Keys:
- 双指针
Code:
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e5+;
typedef long long LL; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE LL n,p,s[M];
scanf("%lld%lld", &n,&p);
for(LL i=; i<n; i++)
scanf("%lld", &s[i]);
sort(s,s+n);
LL i=,j=,step=;
while(j < n)
{
while(j<n && s[j]<=s[i]*p)
j++;
if(j-i > step)
step = j-i;
i++;
j=i+step;
}
printf("%lld", step); return ;
}
PAT_A1085#Perfect Sequence的更多相关文章
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- A1085. Perfect Sequence
Given a sequence of positive integers and another positive integer p. The sequence is said to be a & ...
- 1085. Perfect Sequence
Given a sequence of positive integers and another positive integer p. The sequence is said to be a “ ...
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- 1085 Perfect Sequence (25 分)
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- pat1085. Perfect Sequence (25)
1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Give ...
- PAT Perfect Sequence (25)
题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...
随机推荐
- express框架中router组件的app.use和app.get
首先看例子: var express = require('express'); var router = express.Router(); var index = require('./route ...
- 线段树(two value)与树状数组(RMQ算法st表)
士兵杀敌(三) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进行比 ...
- vue + element 创建教程
一.环境准备 node安装 node版本:v10.15.3 node下载地址:https://nodejs.org/zh-cn/ vue-cli安装 全局安装vue-cli npm install - ...
- elasticsearch 基础 —— URI搜索
URI搜索 可以通过提供请求参数使用URI来执行搜索请求.使用此模式执行搜索时,并非所有搜索选项都会暴露.这是一个例子: GET twitter/_search?q=user:kimchy 示例响应: ...
- 云中沙箱学习笔记1-快速部署并使用MySQL数据库
1.1 背景知识 业务背景 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于Oracle旗下产品.MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面MyS ...
- zabbix入门之配置邮件告警
zabbix入门之配置邮件告警 邮件环境搭建 使用本地邮箱账号发送邮件 zabbix-server 端安装 mailx .sendmail或者psotfix 服务,系统默认安装好了postfix #安 ...
- C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable
C++中使用函数strcpy时出现问题: 解决方案: 在文件开头添加语句: #pragma warning(disable:4996) done! 剑指offer: 第一题:赋值运算符函数 #incl ...
- C#基础知识之类和结构
虽然项目中一直在使用类.结构体等类型,仔细琢磨,还真无法系统的说出个所以然.记录一下类.结构体.类和结构体区别 一.类 对于类,大家都特别熟悉.简单的介绍一下类的结构,然后记录一下Class需要注意的 ...
- DevOps打造端到端的价值交付
首先就要来说下什么是端到端: 敏捷帮助我们解决了开发域从计划到测试(部分测试内容)的问题 持续集成帮助解决了从计划到测试完成的过程 持续发布解决了从计划到待发布的过程 持续部署解决了从计划到已上线的过 ...
- bzoj4007 & loj2111 [JLOI2015]战争调度 复杂度分析+树上背包
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4007 https://loj.ac/problem/2111 题解 同 [NOI2006]网络 ...