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 ...
随机推荐
- Docker技术入门与实战 第二版-学习笔记-4-Dockerfile外其他生成镜像的方法
其它生成镜像的方法 即除了标准地使用Dockerfile来生成镜像外,还有一些其他的方法 1)从 rootfs 压缩包导入 格式:docker import [选项] <文件>|<U ...
- linux 文件夹和文件操作
1.统计目录有多少个文件数 find ./company -type f | wc -l 2.删除文件夹中的文件 rm -f * #最经典的方法,删除当前目录下的所有类型的文件 rsync --del ...
- MSP430F5438A的串口
设置串口,最关键的是波特率的设置,推荐一个网站,很方便地计算波特率,http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP43 ...
- Android漏洞——将Android恶意代码隐藏在图片中
研究人员发现了Android上又一个严重的安全漏洞:将Android恶意代码隐藏在图片中(Hide Android Applications in Images). 在该漏洞向外界公开之前,Googl ...
- 【WPF】给TextBox添上Label
原文:[WPF]给TextBox添上Label 引言 在客户端开发中,要说出现频率大的控件,必定有TextBox的身影.然而在TextBox的旁边通常得有个基友Label,形影不离.为此,我们 ...
- python面试题(四)
一.数据类型 1.字典 1.1 现有字典 dict={‘a’:24,‘g’:52,‘i’:12,‘k’:33}请按字典中的 value 值进行排序? sorted(dict.items(),key=l ...
- effective c++ 笔记 (35-40)
//---------------------------15/04/24---------------------------- //#35 考虑virtual函数以外的其他选择 { /* 1: ...
- 小知识点--crontab
前言 这两周学了很多东西,还把golang语言基本掌握了,收获还是挺多的.在做安全的过程中,有很多需要定时执行的任务,比如抓取主机数量,端口数据等,这都逃不开linux中的crontab命令,今天分享 ...
- HTML 图像实例
61.插入图像本例演示如何在网页中显示图像.图像标签(<img>)和源属性(Src)在 HTML 中,图像由 <img> 标签定义. <img> 是空标签,意思是说 ...
- Python魔术世界 1 如何使用Visual Studio在WIN10中一键安装Python3入门编程环境并测试Django
本文通过VS安装Python和Django的环境,创建了一个Web程序,前后5分钟的操作,让你快速入门Python的编程世界,各种Python和Django的概念会在实战中给你娓娓道来. Django ...