PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064
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 <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
long long a[maxn]; int main() {
int N, p, temp = 1;
scanf("%d%d", &N, &p);
for(int i = 1; i <= N; i ++)
scanf("%lld", &a[i]);
sort(a + 1, a + 1 + N);
for(int i = 1; i <= N; i ++) {
for(int j = temp + i; j <= N; j ++) {
if(a[j] <= a[i] * p)
temp = j - i + 1;
else break;
}
}
printf("%d\n", temp);
return 0;
}
暴力 离考试越来越近 心慌慌
PAT 甲级 1085 Perfect Sequence的更多相关文章
- PAT甲级——A1085 Perfect Sequence
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
- 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 ...
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 1085 Perfect Sequence (25 分)
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- pat甲级1085
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- 1085. Perfect Sequence
Given a sequence of positive integers and another positive integer p. The sequence is said to be a “ ...
- 1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
随机推荐
- JAVA框架 Mybaits
注意:我们在resultType中,对于selectlist方法也是projo类.resultType参数的含义是list的泛型的类型. 一:jar包下载: https://github.com/m ...
- JAVA 框架hibernate (三)(数据库更新丢失)
一.场景: 我们在并发操作数据库同一个字段,比如:name:tom age:22这条数据.有2个同时进行操作.A操作该数据的name改成admin,B操作这条数据的age改成:35.然后A先把数据更 ...
- jqgrid editrules参数说明
转载至:jqgrid的editrules参数 以下为内容留存记录. editrules editrules是用来设置一些可用于可编辑列的colModel的额外属性的.大多数的时候是用来在提交到服 ...
- opencv---JPEG图像质量检测代码
参考:http://blog.csdn.net/trent1985/article/details/50904173 根据国外一篇大牛的文章:No-Reference Perceptual Quali ...
- 大数据入门第二十天——scala入门(二)scala基础01
一.基础语法 1.变量类型 // 上表中列出的数据类型都是对象,也就是说scala没有java中的原生类型.在scala是可以对数字等基础类型调用方法的. 2.变量声明——能用val的尽量使用val! ...
- go语言之行--结构体(struct)详解、链表
一.struct简介 go语言中没有像类的概念,但是可以通过结构体struct实现oop(面向对象编程).struct的成员(也叫属性或字段)可以是任何类型,如普通类型.复合类型.函数.map.int ...
- 20155223 实验5 MSF基础应用
20155223 实验5 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode? exploit:漏洞攻击.一个exploit程序肯定会触发系统的一个或多个漏 ...
- 20155232《网络对抗》Exp5 MSF基础应用
20155232<网络对抗>Exp5 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode. exploit:就是利用可能存在的漏洞对目标进行攻击 ...
- 使用Fortify进行代码静态分析(系列文章)
BUG级别:低 Code Correctness(代码正确性) 1.Class does not Implement Equals(类未能实现Equals方法) Dead Code(死亡代码) 1.U ...
- 【调试】Core Dump是什么?Linux下如何正确永久开启?
[调试]Core Dump是什么?Linux下如何正确永久开启?