1030. 完美数列(25)
来源:互联网 发布:淘宝店铺可以不装修吗 编辑:程序博客网 时间:2024/05/21 01:32
给定一个正整数数列,和正整数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
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>using namespace std;int main(){ int N=0,p=0; cin>>N>>p; vector<int> vec; for(int i=0;i<N;i++){ int tmp=0; cin>>tmp; vec.push_back(tmp); } sort(vec.begin(),vec.end()); vector<int>::iterator begin=vec.begin(),end=--vec.end(); for(int i=0;i<vec.size();i++){ for(int j=i;j>=0;j--){ double min=*(begin+j); double max=*(end-(i-j)); if(max<=p*min){cout<<(vec.size()-i)<<endl;return 0;} } } return 0;}
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int N=0,p=0;
cin>>N>>p;
int a[100010];
for(int i=0;i<N;i++){
int tmp=0;
cin>>tmp;
a[i]=tmp;
}
sort(a,a+N);
for(int i=0;i<N;i++){
for(int j=i;j>=0;j--){
double max=a[N-1-(i-j)];
double min=a[j];
if(max<=p*min){cout<<(N-i)<<endl;return 0;}
}
}
return 0;
}
#include<iostream> #include<string> #include<algorithm> using namespace std; #define Max 100000 long long arr[Max+1]; int main() { long long N, P; int ans=1; cin>>N>>P; int i, j; for( i=0; i<N; i++ ) { cin>>arr[i]; } sort(arr,arr+N); for( j=0; j<N; j++ ) for( i=j+ans; i<N; i++ ) { if( arr[i]<=arr[j]*P ){ if( i-j+1>ans ) { ans=i-j+1; } } else break; } cout<<ans<<endl; return 0; }
阅读全文
0 0
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- 1030. 完美数列(25)
- Spring-配置文件加载工具
- Linux(CentOS7)安装zip、unzip命令
- HDU.2640 Queuing (矩阵快速幂)
- opencv(20)---轮廓查找与绘制
- shell命令学习笔记
- 1030. 完美数列(25)
- intellij idea 使用struts2访问action时出现404错误
- NFC的android实现
- c++实现“反应时间”测试
- NFC在Android平台的架构与移植
- NYoj 74 小学生算术
- 非阻塞和协程
- javaWeb 手动建目录树创建web应用并部署
- [时间序列分析][6]--季节差分