HDU 5289 尺取
Assignment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4316 Accepted Submission(s): 1984
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.
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.
4 2
3 1 2 4
10 5
0 3 4 5 2 1 6 7 8 9
28
First Sample, the satisfied groups include:[1,1]、[2,2]、[3,3]、[4,4] 、[2,3]
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define eps 1e-12
int a[];
int main()
{
int n,k,i,t,j;
LL s=;
cin>>t;
while(t--){s=;
cin>>n>>k;
for(i=;i<=n;++i) scanf("%d",&a[i]);
s=n;
int maxn=,minn=,l=;
for(i=;i<=n;++i){
if(a[i]>=a[maxn]) maxn=i;
if(a[i]<=a[minn]) minn=i;
if(a[maxn]-a[minn]<k)
{
s+=i-l;
}
else
{
maxn=minn=i;
for(j=i;j>=;--j)
{
if(a[j]>=a[maxn])
{
if(a[j]-a[minn]>=k) break;
else maxn=j;
}
if(a[j]<=a[minn])
{
if(a[maxn]-a[j]>=k) break;
else minn=j;
} }
l=j+;
s+=i-l;
}
}cout<<s<<endl;
}
return ;
}
HDU 5289 尺取的更多相关文章
- hdu 5672 尺取还是挺好用的
先简单介绍下尺取法 http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是在卡给定条件的时候 不断的改变下标 起点 终点 #inclu ...
- HDU 6205 尺取
容易看出来,扩增一倍,找最长的区间就行了 /** @Date : 2017-09-11 12:43:11 * @FileName: 1012.cpp * @Platform: Windows * @A ...
- 【单调队列+尺取】HDU 3530 Subsequence
acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...
- 【尺取】HDU String
http://acm.hdu.edu.cn/showproblem.php?pid=5672 [题意] 给定一个小写英语字母组成的字符串,求这个字符串一共包含多少个至少有m个不同字母的连续子序列 [思 ...
- 【尺取】HDU Problem Killer
acm.hdu.edu.cn/showproblem.php?pid=5328 [题意] 给定一个长度为n的正整数序列,选出一个连续子序列,这个子序列是等差数列或者等比数列,问这样的连续子序列最长是多 ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- HDU 5178 pairs【二分】||【尺取】
<题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不 ...
- HDU 5672 String 【尺取】
<题目链接> 题目大意:给定一个只由26个小写字母组成的字符串,现在问你至少包含k个不同字母的连续子序列总数有多少. 解题分析:经仔细研究,我们发现,每次尺取到符合要求的最小区间,然后将区 ...
随机推荐
- 《Oracle RAC性能优化》
一 RAC环境 RAC架构,2节点信息 节点1 SQL> show parameter instance NAME TYPE ...
- tcp五层模型
物理层由来:上面提到,孤立的计算机之间要想一起玩,就必须接入internet,言外之意就是计算机之间必须完成组网 物理层功能:主要是基于电器特性发送高低电压(电信号),高电压对应数字1,低电压对应数字 ...
- 获取IE (控件)的所有链接(包括Frameset, iframe)
获取IE (控件)的所有链接(包括Frameset, iframe) IE 顶层 body 节点通过IHTMLElement->get_all 方法无法获取iframe 里面的节点列表 CCom ...
- Mac使用操作
快捷键退出程序:Command + Q 快捷键关闭窗口:Command + W(关闭程序的窗口不一定是退出程序) 单击左上角黑苹果,菜单里面有强制退出 Finder菜单的偏好设置,高级设置菜单里面可以 ...
- hbase(二)
一.HBase简介 1.1简介 hbase是bigtable的开源山寨版本.是建立的hdfs之上,提供高可靠性.高性能.列存储.可伸缩.实时读写的数据库系统.它介于nosql和RDBMS之间,仅能通过 ...
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Fantastic Beasts
地址:http://codeforces.com/gym/101194 题目:略 思路: 这题做法挺多的,可以sam也可以后缀数组,我用sam做的. 1.我自己yy的思路(瞎bb的) 把第一个串建立s ...
- 【java】使用Builder模式,轻松应对动态繁杂的方法参数
背景:在咱编写的图片处理模块里,针对加载这个方法,参数很多,如: /** * 加载图片,经过内存.磁盘.两层缓存如果还没找到,则走http访问网络资源 * @param url 地址 * @param ...
- tomcat服务无响应堆栈分析
tomcat服务突然无响应了,导出内存堆栈和线程堆栈,分析后发现是同步锁使用不合理导致的. [root@prd-dtb-web-01 ~]# [root@prd-dtb-web-01 ~]# jmap ...
- WWDC 2017 苹果开发者大会
1.更新了系统固件 iOS 11 macOS High Sierra watchOS 4 tvOS 11 2.更新了硬件以及新设备 升级了 iMac 以及 iMac Pro 升级了 MacBook ...
- python3_time模块详解
python提供的时间模块time是需要单独引入: 1.time.sleep(secs)# 推迟调用线程的运行,secs指的是秒 time.sleep(secs) 2.time.time():返回当前 ...