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 ...
随机推荐
- Linux服务正常启动,Linux服务器能访问,但是外部机器不能访问
公司用到了jenkins,就在自己虚拟机里面部署了一个jenkins.部署成功之后,在Linux虚拟机里面能正常访问,但是外部真实机却不能访问.当时的第一反应就是觉得应该是权限问题,猜测会不会是jen ...
- 1481:Maximum sum (前缀和+dp)
[题目描述] 对一个序列A={a1, a2,..., an}给出函数: t1 t2 d(A) = max{ ∑ai + ∑aj | 1 <= s1 <= t1 < s2 <= ...
- Codeforces 1000E We Need More Bosses (边双连通+最长链)
<题目链接> 题目大意:给定一个$n$个节点$m$条边的无向图,问你对任意两点,最多有多少条特殊边,特殊边指删除这条边后,这两个点不能够到达. 解题分析: 特殊变其实就是指割边,题意就是问 ...
- cdn.bootcss.com无法访问 解决方法
今天angularjs的网站突然加载报错,提示Refused to execute script from 'https://cdnjs.com/' because its MIME type ('t ...
- C# form 传参数的几个方法
方法一:传值最先想到的,Form2构造函数中接收一个string类型参数,即Form1中选中行的文本,将Form2的TextBox控件的Text设置为该string,即完成了Form1向Form2的传 ...
- ajax请求超时解决方案
设置timeout的时间,通过检测complete时status的值判断请求是否超时,如果超时执行响应的操作. var ajaxTimeoutTest=$.ajax({ url:'',//请求地址 t ...
- SharePoint创建web应用程序,提示密码不正确
使用版本SharePoint2010: $username="domain\username"$newpassword="xxxxxxxx"stsadm -o ...
- Codeforces Round #394 (Div. 2) - B
题目链接:http://codeforces.com/contest/761/problem/B 题意:给定一个环形跑道.里面有n个障碍,跑道长度为L.然后有两个人在两个起点(起点可能相同),每个人都 ...
- python爬虫:抓取下载视频文件,合并ts文件为完整视频
1.获取m3u8文件 2.代码 """@author :Eric-chen@contact :sygcrjgx@163.com@time :2019/6/16 15:32 ...
- 第二节:链接mongodb服务器
查看mongodb的使用说明 版本是3.6.0 options 选项 指的是用户名和密码 address 数据库地址 数据库格式是 ip:端口/数据库 192.168.0.5:999/foo 链接本 ...