PAT (Basic Level) Practise (中文) 1030. 完美数列(25)
来源:互联网 发布:windows安装更新慢 编辑:程序博客网 时间:2024/06/05 12:35
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 82 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[n];
int arr2[]=new int[n];
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);
}
}
阅读全文
0 0
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise (中文) 1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT BASIC LEVEL 1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1015. 德才论 (25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1050. 螺旋矩阵(25)
- PAT (Basic Level) Practise (中文)1045快速排序(25)
- [数位DP AC自动机] Codeforces 434C. Tachibana Kanade's Tofu
- [SPRD]展讯平台 LCD(Mipi) 加载流程分析
- Ehcache详细解读
- Git SSH Key生成步骤说明
- 懂得如何通过研究找到答案
- PAT (Basic Level) Practise (中文) 1030. 完美数列(25)
- 为什么很多做人脸的Paper会最后加入一个Local Connected Conv?
- mark
- [SPRD]展讯平台 LCD(Mipi)移植步骤及问题归纳
- CocoaPods: pod search 搜索类库失败的解决办法
- Java小程序之1000000数字判断是否为回数
- 保存退出vim编辑
- 全文检索之sphinx源码分析--优化
- Python自学笔记