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 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注意点:1.int*int 的范围必须用long long;
2.if(a[n-1]<=x) return n;
#include<bits/stdc++.h>
using namespace std; const int maxn =; int a[maxn]; int n,p; int binary_Search(int i,long long x){ if(a[n-]<=x)
return n; int left=i+,right=n-; while(left<right){
int mid = (left+right)/; if(a[mid]>x){
right =mid;
}else{
left= mid+;
}
} return left; } int main(){ cin>>n>>p; for(int i=;i<n;i++)
cin>>a[i]; sort(a,a+n); int ans=; for(int i=;i<n;i++){ // int j=binary_Search(i,(long long)a[i]*p); int j=upper_bound(a+i+,a+n,(long long)a[i]*p)-a; ans=max(ans,j-i); // cout<<j<<" "<<i<<endl;
} cout<<ans<<endl; return ; }
1085 Perfect Sequence (25 分)的更多相关文章
- 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 ...
- 【PAT甲级】1085 Perfect Sequence (25 分)
题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- 1085. Perfect Sequence (25)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...
- PAT (Advanced Level) 1085. Perfect Sequence (25)
可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...
- 1085. Perfect Sequence (25)-水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- pat1085. Perfect Sequence (25)
1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Give ...
- 1085 Perfect Sequence (25 分)
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
随机推荐
- SQLSERVER 时间日期函数,查询今天日期、昨天、一个星期、半年前的数据
今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0昨天的所有数据:select * from 表名 where D ...
- 监控软件munin安装设置
准备工作需要web环境需要设置epel源 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo 服务器端安装设置 y ...
- AVL树,C语言实现,完整代码,先贴上,讲解稍后
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> #de ...
- 转 Python - openpyxl 读写操作Excel
Python - openpyxl 读写操作Excel openpyxl特点 openpyxl(可读写excel表)专门处理Excel2007及以上版本产生的xlsx文件,xls和xlsx之间 ...
- Python-02 生成器表达式,列表推导式
列表推导式和生成器表达式 列表推导式,生成器表达式1,列表推导式比较直观,占内存2,生成器表达式不容易看出内容,省内存. [ 变量(加工后的数据) for 变量i in 可迭代的数据类型 ] 列表 ...
- add characteristic to color
Problem: add a new Char. name D_COI6 that the description is Injected coloration #7 (COI6) in the D_ ...
- 案例:forEach和some区别
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 整合mybatis时报错:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...
- 统计List中相同的元素
public static <E> List<E> getCommonsElements(List<E> list) { return list.stream() ...
- 第二章 部署Kubernetes集群准备环境
一.centos7开机自动联网设置 1.使用root用户登录进入Linux,打开进去终端 2.在终端中输入:cd /etc/sysconfig/network-scripts 3.ll命令找到目录下 ...