1085. Perfect Sequence (25)-水题

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>

using namespace std;
const int maxn=100000+5;
long long a[maxn];
int main()
{
    int n,p;
    scanf("%d %d",&n,&p);
    int minidx=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    int cnt=0,maxlen=0;
    for(int i=0;i<n;i++){
        if(a[i]<=a[minidx]*p){
            cnt++;
        }
        else{
            if(cnt>maxlen)
                maxlen=cnt;
            minidx++;
            cnt--;
            i--;
        }
    }
    //最后不要忘了还要判断下。。。
    if(cnt>maxlen)
        maxlen=cnt;
    printf("%d\n",maxlen);
    return 0;
}

时间: 2024-10-23 22:06:55

1085. Perfect Sequence (25)-水题的相关文章

1085. Perfect Sequence (25)-PAT甲级真题

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

1085. Perfect Sequence (25)【二分查找】——PAT (Advanced Level) Practise

题目信息 1085. Perfect Sequence (25) 时间限制300 ms 内存限制65536 kB 代码长度限制16000 B 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 minim

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

pat 1085. Perfect Sequence (25)

时间限制 300 ms 内存限制 32000 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

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

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

可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n; long long k; long l

pat1085. Perfect Sequence (25)

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

POJ 2081 Recaman&#39;s Sequence(水题)

[题意简述]:这个题目描述很短,也很简单.不再赘述. [分析]:只需再加一个判别这个数是否出现的数组即可,注意这个数组的范围! // 3388K 0Ms #include<iostream> using namespace std; #define Max 500001 int a[Max]; bool b[10000000] = {false}; // b的数据范围是可以试出来的- void init() { a[0] = 0; b[0] = true; for(int m = 1;m<

A1085. 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 pa