题目描写叙述

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. K-means algorithm----PRML读书笔记

    The K-means algorithm is based on the use of squared Euclidean distance as the measure of  dissimila ...

  2. SpringBoot + MyBatis(注解版),常用的SQL方法

    一.新建项目及配置 1.1 新建一个SpringBoot项目,并在pom.xml下加入以下代码 <dependency> <groupId>org.mybatis.spring ...

  3. Redis(三)-Ubuntu下安装

    Ubuntu 下安装 在 Ubuntu 系统安装 Redi 可以使用以下命令: $sudo apt-get update $sudo apt-get install redis-server 启动 R ...

  4. MySql c#通用类 转

    using System;using System.Data;using System.Configuration;using System.Collections.Generic;using Sys ...

  5. Md2All,让公众号完美显示Latex数学公式

    当公众号遇上Latex 大家都知到,公众号连代码块都不支持,更不要说功能强大的Latex公式了.那在Md2All之前,如果想在公众号上显示Latex公式应该怎么办呢? 最通常的做法就是在某个支持Lat ...

  6. 设置浏览器让js报错

    ie-工具---internet选项--高级--“禁用脚本提示”前面那个框的勾去掉---“显示每个脚本错误的通知”给该项打勾 注意:此时是静态页面很容易提示出错误的行号,但是当js是动态页面的时候,浏 ...

  7. VMWare虚拟机移动

    1.  背景: 虚拟机:VM3 原安装路径:C:\Users\Administrator\Documents\Virtual Machines 移动到目标路径:D:\Virtual Machines ...

  8. VMWare虚拟机Centos 6.9中的 linux 配置静态ip地址上外网

    1.查看网络 # ifconfig 发现网络还没有配置,ping不通 2.修改网卡配置文件 # vim /etc/sysconfig/network-scripts/ifcfg-eth0 添加如下配置 ...

  9. 【Oracle】进入sqlplus 删除键backspace时出现^H

    当oracle进入sqlplus后,输入命令时候出现错误,我们按平时的习惯使用backspace键删除错误信息,此时会出现^H 解决办法:进入sqlplus之前,使用stty erase '^H'命令 ...

  10. JAVA;使用java.awt.Image的不稳定性

    在使用awt的image时候,不是能时时获取到图像的宽和高, GetWidth()函数偶尔得到的值为-1,暂时没有找到解决方法. 代码: public class picture extends JF ...