当前位置:网站首页>B1030 perfect sequence
B1030 perfect sequence
2022-07-27 05:20:00 【Ye Chen】
1030 Perfect sequence (25 branch )
Given a sequence of positive integers , And positive integers p, Let the maximum of this sequence be M, The minimum is m, If M≤mp, We call this sequence perfect .
Now, given the parameters p And some positive integers , Please choose as many numbers as you can to form a perfect sequence .
Input format :
The first line of input gives two positive integers N and p, among N(≤10 Of 5 Power ) Is the number of positive integers entered ,p(≤10 Of 9 Power ) Is the given parameter . The second line gives N A positive integer , No more than 10 Of 9 Power .
Output format :
How many numbers can you choose to output in a row? You can use them to form a perfect sequence .
sample input
10 8
2 3 20 4 5 1 6 7 8 9
sample output
8
Topic analysis :
- After storing the array data , Use it in time sort Sort , Convenient for future operation
- Test point 4 Timeout problem : You can save a temporary variable first j,j Is the maximum number in the current sequence . finish while Update in time after the cycle count Value
- Be careful mp The numerical range of
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,p,count=0;
cin>>n>>p;
vector<int> a;
for(int i=0;i<n;i++){
int x;
cin>>x;
a.push_back(x);
}
sort(a.begin(),a.end());
int j=0;// Time spent optimizing code ------ Test point 4 The key to timeout
for(int i=0;i<n-count;i++){
long long int mp=(long long)a[i]*p;// Take care mp Value int There is no room for ------- Test point 5
while(j<n&&a[j]<=mp){
j++;
}
count=max(count,j-i);
}
cout<<count;
return 0;
}
边栏推荐
- Counting Nodes in a Binary Search Tree
- B1028 人口普查
- Scientific Computing Library -- Matplotlib
- Use of file i/o in C
- Database design - relational data theory (ultra detailed)
- B1025 reverse linked list*******
- 精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
- How to store the startprocessinstancebykey method in acticiti in the variable table
- 支付流程如何测试?
- 求组合数(最强优化)
猜你喜欢
![[acwing] solution to the 61st weekly match](/img/31/765f4ce9f779e8093668e7606e0198.png)
[acwing] solution to the 61st weekly match

JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory

JVM上篇:内存与垃圾回收篇--运行时数据区四-程序计数器

2021 OWASP top 5: security configuration error

ERROR! MySQL is not running, but PID file exists

What should test / development programmers over 35 do? Many objective factors

Li Kou achieved the second largest result

辗转相除法

Detailed description of polymorphism

OFDM 16 lecture 2-ofdm and the DFT
随机推荐
B1021 个位数统计
JVM上篇:内存与垃圾回收篇十一--执行引擎
Dialog data transfer
来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
34. Analyze flexible.js
Set static IP for raspberry pie
B1023 group minimum
Bean的生命周期&&依赖注入*依赖自动装配
JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack
[optical flow] - data format analysis, flowwarp visualization
听过最自律的一句话: 那些我难以言表 不作声响
Database design - relational data theory (ultra detailed)
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
Counting Nodes in a Binary Search Tree
How to test the payment process?
Advantages of smart exhibition hall design and applicable industry analysis
Detailed description of polymorphism
Card drawing program simulation
抽卡程序模拟