当前位置:网站首页>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;
}
边栏推荐
- LeetCode之6 ZigZag Conversion
- The difference between strlen and sizeof
- JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
- JVM Part 1: memory and garbage collection part 11 -- execution engine
- JVM Part 1: memory and garbage collection part 3 - runtime data area - overview and threads
- 二、MySQL高级
- DBUtils
- Raspberry pie RTMP streaming local camera image
- Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
- SSM framework integration
猜你喜欢

JVM Part 1: memory and garbage collection part 11 -- execution engine

Standard dialog qmessagebox

JVM Part 1: memory and garbage collection part 7 -- runtime data area heap

Database connection pool & Druid usage

Raspberry pie output PWM wave to drive the steering gear

35. Scroll

Use of collection framework

How to store the startprocessinstancebykey method in acticiti in the variable table

Critical path principle

JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack
随机推荐
Flexible array and common problems
JVM上篇:内存与垃圾回收篇六--运行时数据区-本地方法&本地方法栈
Scientific Computing Library -- Matplotlib
2021 OWASP top 6-10 collection
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
The interface can automatically generate E and other asynchronous access or restart,
JVM Part 1: memory and garbage collection part 7 -- runtime data area heap
Solution to Dlib installation failure
Set static IP for raspberry pie
Dialog data transfer
JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位
JVM上篇:内存与垃圾回收篇十二--StringTable
2022年郑州轻工业新生赛题目-打死我也不说
Solution and principle analysis of feign call missing request header
File processing (IO)
牛客剑指offer--JZ12 矩阵中的路径
Quoted popular explanation
B1031 查验身份证
SQL数据库→约束→设计→多表查询→事务
数据库连接池&&Druid使用