题目描写叙述

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. Python入门 不必自己造轮子

    操作list list切片 字符串的分割 字符串的索引和切片 读文件 f = file('data.txt') data = f.read() print data f.close() 写文件 dat ...

  2. CRMEB系统就是集客户关系管理+营销电商系统,能够真正帮助企业基于微信公众号、小程序实现会员管理、数据分析,精准营销的电子商务管理系统。可满足企业新零售、批发、分销、等各种业务需求。

    **可以快速二次开发的开源小程序商城系统源码**源码开源地址:https://github.crmeb.net/u/LXT 项目介绍: CRMEB系统就是集客户关系管理+营销电商系统,能够真正帮助企业 ...

  3. CAS配置记录

    CAS配置(1)之证书配置 CAS配置(2)之主配置 CAS配置(3)之restful-api接入接口

  4. Cracking the Coding Interview 6.5

    There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. If it ...

  5. ACM_螺旋填数

    螺旋填数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 一天,小明在研究蜗牛的壳时,对其螺旋状的花纹感到十分有趣.于是他回到了家 ...

  6. “阻塞”与"非阻塞"与"同步"与“异步"

    链接:http://www.zhihu.com/question/19732473/answer/20851256来源:知乎 “阻塞”与"非阻塞"与"同步"与“ ...

  7. font使用

    font连写属性 font-style  font-variant font-weight  font-size/line-height  font-family font-size与font-fam ...

  8. 子线程更新UI

    https://www.cnblogs.com/joy99/p/6121280.html

  9. mysqlslap对mysql进行压力测试

    mysqlslap是从5.1.4版开始的一个MySQL官方提供的压力测试工具.通过模拟多个并发客户端访问MySQL来执行压力测试,并且能很好的对比多个存储引擎在相同环境下的并发压力性能差别. mysq ...

  10. Java:Java 队列的遍历

    Java队列到底有没有可以遍历的功能呢?暂且试一下吧 参考链接:stl容器遍历测试 1.LinkedList实现简单遍历 for(Iter =LocTimesSerials.size()-1; iSe ...