当前位置:网站首页>hdu5289(Assignment)
hdu5289(Assignment)
2022-07-27 10:14:00 【51CTO】
Description
Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a group, the difference of the ability of any two staff is less than k, and their numbers are continuous. Tom want to know the number of groups like this.
Input
In the first line a number T indicates the number of test cases. Then for each case the first line contain 2 numbers n, k (1<=n<=100000, 0<k<=10^9),indicate the company has n persons, k means the maximum difference between abilities of staff in a group is less than k. The second line contains n integers:a[1],a[2],…,a[n](0<=a[i]<=10^9),indicate the i-th staff’s ability.
Output
For each test,output the number of groups.
Sample Input
Sample Output
The question : Given a sequence of positive integers , Ask how many consecutive subsequences there are , The difference between the maximum value and the minimum value is less than k?
Answer key : Magical monotonous queue , Maintain minimum and maximum values with a monotonically increasing and decreasing queue , Use two front and rear pointers , The front pointer points to the left endpoint of the current interval , The back pointer points to the current element . If new elements are currently added ,max-min>=k, Then it is at least different from the new elements k All elements before that element of will be invalidated , That is out of the team . The answer of each operation is added with the maximum distance that the new element can extend to the left .
Example :n=6,k=3, The sequence is 5 3 5 2 3 4.q1 Increase the queue for monotony ,q2 Reduce the queue for monotonicity .
At this time, I found out q1 Medium minimum and q2 The difference between the maximum values in 3>=k, Then start out .
So the final answer is 12
边栏推荐
- pytorch中对BatchNorm2d()函数的理解
- Shell operator, $((expression)) "or" $[expression], expr method, condition judgment, test condition, [condition], comparison between two integers, judgment according to file permission, judgment accor
- RobotFramework+Eclispe环境安装篇
- Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号
- 面试必备:虾皮服务端15连问
- 备战金九银十Android面试准备(含面试全流程,面试准备工作面试题和资料等)
- 并发之线程状态转换
- Easy to understand! Graphic go synergy principle and Practice
- Engineering survey simulation volume a
- 数据库性能系列之子查询
猜你喜欢

卸载CUDA11.1

Anchor free detector: centernet

Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children

Qt 学习(二) —— Qt Creator简单介绍

Huawei switch dual uplink networking smart Link Configuration Guide

Anchor Free检测器:CenterNet

Oracle RAC 19C PDB instance is down

Data visualization

PCL各模块概述(1.6)

When I went to oppo for an interview, I got numb
随机推荐
3D人脸重建:Joint 3D Face Reconstruction and Dense Alignment with position Map Regression Network
历时一年,论文终于被国际顶会接收了
Huawei switch dual uplink networking smart Link Configuration Guide
What happens if the MySQL disk is full? I really met you!
Introduction to Matlab real time editor
Shell variables, system predefined variables $home, $pwd, $shell, $user, custom variables, special variables $n, $, $*, [email protected],
文件上传漏洞相关
When I went to oppo for an interview, I got numb
StyleGAN论文笔记+修改代码尝试3D点云生成
Snowflake vs. databricks who is better? The latest war report in 2022
Decision tree principle and case application - Titanic survival prediction
Interview Essentials: shrimp skin server 15 consecutive questions
Anaconda安装(非常详细)
open3d库的安装,conda常用指令,导入open3d时报这个错误Solving environment: failed with initial frozen solve. Retrying w
Shell read read console input, use of read
Easy to understand! Graphic go synergy principle and Practice
Is Damon partgroupdef a custom object?
NVIDIA geforce experience login error: the verifier failed to load. Please check your browser settings, such as the advertisement interceptor (solution)
System parameter constant table of system architecture:
Come on, chengxujun