PAT.A1085. Perfect Sequence

原创 2018年04月15日 23:57:04

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
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <iostream>
using namespace std;


long long a[100010];
int main(){
	int n, p;
	scanf("%d%d", &n, &p);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sort(a, a + n);
	int count = -1;
	int i = 0, j = 0;
	while (j <n) {
		
		while (a[i] * p>=a[j]&&j<n) j++;
	//	printf("%lld %d %d\n", a[j],i,j);
		count = max(count, j - i);
		i++;
	}
	printf("%d",count);
	return 0;
	
}

Oracle数据库

本课程主要讲解如下内容:Oracle体系结构、Oracle 基础管理、SQL 语言、Sequence和同义词、数据字典及用户管理、E-R模型、Power Designer设计工具。在本课程讲解之中会提供有相应的练习习题以及综合案例分析,帮助读者迅速掌握Oracle数据库的核心开发技能。官方QQ群:612148723。
  • 2016年12月31日 09:04

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

题目如下: Given a sequence of positive integers and another positive integer p. The sequence is s...
  • xyt8023y
  • xyt8023y
  • 2015-08-11 14:27:05
  • 1451

pat 1085. Perfect Sequence (25)

pat 1085. Perfect Sequence (25)
  • nan327347465
  • nan327347465
  • 2014-09-06 21:58:54
  • 1952

【PAT】1085. Perfect Sequence (25)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1085 ti
  • litoupu
  • litoupu
  • 2014-11-05 15:48:03
  • 1394

1085. Perfect Sequence 解析

最佳序列。 就是从给的序列里面,找最长的序列,满足最大值小于等于最小值*p 先给序列排序。从最小的开始,找能找到的最大值的位置,计算长度。 这里不能直接循环,会超时,需要二分查找,找小于等于理想...
  • sheepyWYY
  • sheepyWYY
  • 2017-05-09 09:12:44
  • 91

PAT (Advanced Level) 1085. Perfect Sequence (25) 贪心算法

Given a sequence of positive integers and another positive integer p. The sequence is said to be a "...
  • tuzigg123
  • tuzigg123
  • 2015-07-30 15:17:32
  • 418

PAT Perfect Sequence (25)

题目描述 Given a sequence of positive integers and another positive integer p. The sequence is said to b...
  • u011694809
  • u011694809
  • 2015-06-08 10:59:37
  • 599

PAT 甲级 1085. Perfect Sequence (25)

Given a sequence of positive integers and another positive integer p. The sequence is said to be a "...
  • zengjingchao
  • zengjingchao
  • 2017-10-05 18:07:03
  • 61

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

1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000...
  • jtjy568805874
  • jtjy568805874
  • 2016-03-25 14:56:24
  • 301

Python实现Pat 1085. Perfect Sequence (25)

题目Given a sequence of positive integers and another positive integer p. The sequence is said to be a...
  • YCHANTY
  • YCHANTY
  • 2017-12-06 23:41:05
  • 22
收藏助手
不良信息举报
您举报文章:PAT.A1085. Perfect Sequence
举报原因:
原因补充:

(最多只允许输入30个字)