PAT (Basic Level) Practise (中文) 1030. 完美数列(25)
2017-09-02 09:39
441 查看
1030. 完美数列(25)
时间限制300 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CAO, Peng
给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。
现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。
输入格式:
输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)是给定的参数。第二行给出N个正整数,每个数不超过109。
输出格式:
在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。
输入样例:
10 8 2 3 20 4 5 1 6 7 8 9
输出样例:
8
//部分正确5分
import java.util.Arrays;
import java.util.Scanner;
public class num1030 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int p=input.nextInt();
int arr1[]=new int
;
int arr2[]=new int
;
for (int i = 0; i < arr2.length; i++) {
arr1[i]=input.nextInt();
arr2[i]=arr1[i];
}
Arrays.sort(arr1);
int m=arr1[0];
int M=arr1[arr1.length-1];
/* int cnt = 1;
for (int i = n-1; i >= 1; i--) {
int temp = 1;
int M = arr1[i];
for (int j = i-cnt; j >= 0 && M * 1.0 / arr1[j] <= p ; j--) {
temp = i - j + 1;
}
cnt = cnt > temp ? cnt : temp;
}
用这些代码代替下面那些,测试点四超时,其余正确
System.out.println(cnt);*/
int count=0;
for (int i = 0; i < arr1.length; i++) {
if (arr1[i]<=m*p) {
count++;
}
}
System.out.println(count);
}
}
相关文章推荐
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)-1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Ba 4000 sic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise:1030. 完美数列
- PAT BASIC LEVEL 1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1005. 继续(3n+1)猜想 (25) C语言
- PAT (Basic Level) Practise (中文)- 1005. 继续(3n+1)猜想 (25)
- PAT (Basic Level) Practise (中文)1049. 数列的片段和(20)
- PAT (Basic Level) Practise (中文)1070. 结绳(25)
- PAT (Basic Level) Practise (中文)1045. 快速排序(25) C语言
- PAT (Basic Level) Practise (中文)1025. 反转链表 (25)C语言
- PAT (Basic Level) Practise (中文)1010. 一元多项式求导 (25)
- PAT (Basic Level) Practise (中文) 1040. 有几个PAT(25)
- PAT (Basic Level) Practise (中文)1010. 一元多项式求导 (25)
- PAT (Basic Level) Practise (中文)1015. 德才论 (25) C语言
- PAT (Basic Level) Practise (中文)1025. 反转链表 (25)
- PAT (Basic Level) Practise (中文) 1060. 爱丁顿数(25)
- PAT (Basic Level)1030. 完美数列