1085. Perfect Sequence (25)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng

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 (<= 105) is the number of integers in the sequence, and p (<= 109) is the parameter. In the second line there are N positive integers, each is no greater than 109.

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

提交代码

 #include<cstdio>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
long long line[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
long long n,p;
scanf("%lld %lld",&n,&p);
int i,j;
for(i=;i<n;i++){
scanf("%lld",&line[i]);
}
sort(line,line+n);
int amount;
long long cur=line[]*p;
for(j=;j<n&&line[j]<=cur;j++);//j指针
amount=j;
for(i=;i<n&&j<n;i++){//这里的j<n是为了避免不必要的循环
cur=line[i]*p;
for(;j<n&&line[j]<=cur;j++);
if(j-i>amount){
amount=j-i;
}
}
printf("%d\n",amount);
return ;
}

pat1085. Perfect Sequence (25)的更多相关文章

  1. 1085. Perfect Sequence (25) -二分查找

    题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  2. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  3. 1085 Perfect Sequence (25 分)

    Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...

  4. PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]

    题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...

  5. PAT甲级 Perfect Sequence (25) 记忆化搜索

    题目分析: 意思是要求对于一个给出的数组,我们在其中尽可能多选数字,使得所选数字的max <= min * p,而由于数据量较大直接二层循环不加优化实现是不现实的,由题意得知,对于数字序列的子序 ...

  6. 1085. Perfect Sequence (25)

    the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...

  7. PAT (Advanced Level) 1085. Perfect Sequence (25)

    可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...

  8. 1085. Perfect Sequence (25)-水题

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. 【PAT甲级】1085 Perfect Sequence (25 分)

    题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...

随机推荐

  1. 输出缓存与CachePanel

    缓存的级别 缓存的作用自不必说,提高系统性能最重要的手段之一.上至应用框架,下至文件系统乃至CPU,计算机中各部分设计都能见到缓存的身影.许多朋友一直在追求如何提高Web应用程序的性能,其实最容易被理 ...

  2. PHP二维数组,根据多个字段来排序

    如果是最最常见的二维数组排序, 大多数情况下也只用到二维: 用php内置函数 array_multisort( )  是最简单的: <?php 假设, $arr 是一个二维数组, $arg1是取 ...

  3. MySQL的limit优化

    mysql的分页比较简单,只需要limit offset,length就可以获取数据了,但是当offset和length比较大的时候,mysql明显性能下降 1.子查询优化法 先找出第一条数据,然后大 ...

  4. ServerSocket01

    ServerSocket表示服务端套接字:我们首先来看下其中的一个构造器: public ServerSocket(int port,int backlog) throws IOException 其 ...

  5. 第3章 机器学习的典型应用 3-4 典型应用-ctr预估和协同过滤

    ctr预估,用户点击率的预估.这个算法的名字叫ctr预估,但是它背后算法是线性的逻辑回归. 现在的推荐系统除了可能会用关联规则之外,现在还有一些所谓的更新的协同过滤的算法.

  6. Lua中的点、冒号与self

    Lua中的点.冒号与self,它们之间的关系主要体现在函数的定义与调用上,Lua在函数定义时可以用点也可以用冒号,如: function mytable.fun(p) return p end fun ...

  7. URL中#符号的作用

    转自http://blog.sina.com.cn/s/blog_6f9eb2dd0100sk97.html 一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如,       ...

  8. Linux下查看文件编码,文件编码格式转换和文件名编码转换

    linux相关   2008-10-07 10:46   阅读1392   评论0   字号: 大大  中中  小小  如果你需要在Linux中 操作windows下的文件,那么你可能会经常遇到文件编 ...

  9. centos运行netcore error:package: ‘Microsoft.AspNetCore.Antiforgery‘, version: ‘2.0.3‘

    Error: An assembly specified in the application dependencies manifest (*.*.deps.json) was not found: ...

  10. Dapper 增删改查

    0.数据库及实体类 create table Users ( Id ,) primary key, Name nvarchar() not null, Password nvarchar() not ...