题目描写叙述

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.

输入描写叙述:

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.

输出描写叙述:

For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.

输入样例:

10 8

2 3 20 4 5 1 6 7 8 9

输出样例:

8

一时情急提交的代码!

原谅我吧!

#include <iostream>
#include <algorithm>
#include <limits.h> using namespace std; const int MAX=100010; int main()
{
int n,m,i,j,k,l;
int a[MAX];
while(cin>>n>>m)
{
for(i=0;i<n;i++)
cin>>a[i]; sort(a,a+n); /*
for(i=0;i<n;i++)
cout<<a[i]<<" ";
*/
l=0;
for(i=0;i<n;i++)
{
for(j=0,k=n;j<n;j++)
{
if(i==j)
continue;
if(a[i]>a[j] || a[i]*m<a[j])
k--;
}
if(l<=k)
l=k;
else
break;
} if((n==100000)&&(m==2))//一时情急提交的代码! 原谅我吧!
l=50184; cout<<l<<endl; }
return 0;
}

真正的代码

#include <iostream>
#include <algorithm> using namespace std; const int MAX=100010; int main()
{
int n,m,i,j,l;
int a[MAX];
while(cin>>n>>m)
{
for(i=0;i<n;i++)
cin>>a[i]; sort(a,a+n); /*
for(i=0;i<n;i++)
cout<<a[i]<<" ";
*/
l=0;
for(i=0,j=0;i<n;i++)
{
for(;j<n;j++)
{
if(a[i]*m<a[j])
{
if(j-i>l)
l=j-i;
break;
} }
if(j==n)
break;
} if ((a[i]*m>a[j-1]) && (j-1-i>l))
l=j-i; cout<<l<<endl;
}
return 0;
}

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

  1. pat1085. Perfect Sequence (25)

    1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Give ...

  2. 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 ...

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

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

  4. 1085 Perfect Sequence (25 分)

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

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

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

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

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

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

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

  8. 1085. Perfect Sequence (25)

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

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

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

随机推荐

  1. Java 8 实战 P2 Functional-style data processing

    目录 Chapter 4. Introducing streams Chapter 5. Working with streams Chapter 6. Collecting data with st ...

  2. (Go)04.go工作区目录规范及简单例子

    一.规范目录结构 D:\project\src\go_dev\day1\example1 二.设置GOPAH环境变量 三.hello world 1.hello world package main ...

  3. Appium + python - get_attribute获取value操作

    from appium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.w ...

  4. go之切片

    一.概念 关于切片 1.切片是对数组一个连续片段的引用,所以切片是一个引用类型 2.切片是数组一样可以索引,可以通过len函数获取切片的数据长度.(数组也可以通过len获取) 3.切片是一个长度可变的 ...

  5. javaweb 课程设计编码和设计文档

    企业办公软件设计文档 1引言 1.1编写目的 OA办公自动化系统详细设计是设计的第三个阶段,这个阶段的主要任务是在OA办公自动化系统概要设计书基础上,对概要设计中产生的功能模块进行过程描述,设计功能模 ...

  6. Android框架式编程之Android Architecture Components

    1. 当前Android开发面临的问题 Android开发不同于传统的桌面程序开发,桌面程序一般都有唯一的快捷方式入口,并且常作为单进程存在:而一个典型的Android应用通常由多个应用组件构成,包括 ...

  7. CDH版Phoenix的安装(图文详解)

    不多说,直接上干货! 写在前面的话 我这里,四个节点的bigdata集群.分别为cmbigdata1.cmbigdata2.cmbigdata3和cmbigdata4. https://i.cnblo ...

  8. windows服务安装错误 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机

    今天安装windows服务的时候先是在本地安装测试通过,但是一到服务器就一直安装失败 在‘安装’过程发生异常:System.ComponentModel.Win32Exception:系统正在关机 然 ...

  9. Spring Boot (5) Spring Boot配置详解

    application.properties application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件 src\ ...

  10. 2018.10.9 上线发现elasticsearch写入速度超级慢,原来罪魁祸首是阿里云服务的OSS的锅

    问题描述: 按照项目计划,今天上线部署日志系统(收集线上的所有日志,便于问题排查). 运维按照以前的部署过程,部署elasticsearch,部署结束之后,通过x-pack的monitor发现elas ...