5806 NanoApe Loves Sequence Ⅱ(尺取法)
NanoApe Loves Sequence Ⅱ
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 1585 Accepted Submission(s): 688
Description
NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence with n numbers and a number m on the paper.
Now he wants to know the number of continous subsequences of the sequence in such a manner that the k-th largest number in the subsequence is no less than m.
Note : The length of the subsequence must be no less than k.
Input
The first line of the input contains an integer T, denoting the number of test cases.
In each test case, the first line of the input contains three integers n,m,k.
The second line of the input contains n integers A1,A2,...,An, denoting the elements of the sequence.
1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤109
Output
For each test case, print a line with one integer, denoting the answer.
Sample Output
17 4 24 2 7 7 6 5 1
Sample Output
18
思路
题意:
退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情写下了一个数 m。 他想知道这个数列中有多少个区间里的第 k 大的数不小于 m,当然首先这个区间必须至少要有 k 个数啦。
题解:求数列中多少个区间第k大不小于m,那么我们可以把数列中大于等于m的位置置1,其余置0,那么利用尺取法从头开始扫,找到每个位置开始和为k的区间的末位置,那么就知道总共有多少个区间了
#include<bits/stdc++.h> using namespace std; typedef __int64 LL; const int maxn = 200005; int num[maxn]; int main() { //freopen("input.txt","r",stdin); int T; scanf("%d",&T); while (T--) { int n,m,k,tmp; scanf("%d%d%d",&n,&m,&k); for (int i = 0;i < n;i++) { scanf("%d",&tmp); num[i] = tmp >= m?1:0; } int s = 0,t = 0; LL res = 0,sum = 0; for (;;) { while (t < n && sum < k) { sum += num[t++]; } if (sum < k) break; res += n - t + 1; sum -= num[s++]; } printf("%I64d\n",res); } return 0; }
5806 NanoApe Loves Sequence Ⅱ(尺取法)的更多相关文章
- NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- HDU5806:NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:HDU5806 题意:找出有多少个区间中第k大数不小于m. 分析:用尺取法可以搞定,CF以前有一道类似的题目. #include<cstdio> using namespace ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- HDU 5806 NanoApe Loves Sequence Ⅱ ——(尺取法)
题意:给出一个序列,问能找出多少个连续的子序列,使得这个子序列中第k大的数字不小于m. 分析:这个子序列中只要大于等于m的个数大于等于k个即可.那么,我们可以用尺取法写,代码不难写,但是有些小细节需要 ...
- HDU 5806 NanoApe Loves Sequence Ⅱ
将大于等于m的数改为1,其余的改为0.问题转变成了有多少个区间的区间和>=k.可以枚举起点,二分第一个终点 或者尺取法. #pragma comment(linker, "/STACK ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)
若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans + ...
随机推荐
- 微信小程序热点云笔记demo 开源总结
因为公司的项目需要,我们自己开发了一个微信小程序的云笔记 开源地址 https://github.com/hotapp888/hotapp-notepad 云笔记功能特点:(1)自动微信登录(2)笔记 ...
- 谨慎使用Sql server data tool 架构比对排除
现象:某个架构始终不能更新 VS中使用SSDT很方便,进行架构比对时,可以选择性的更新.但在排除操作上,要相当谨慎.往往排除的并不是一个差异项. 如下图,表或视图的差异,如果有多处,可以选 ...
- 了解npm的文件结构(npm-folders)和配置文件(npm-mrc)
一.npm的文件结构 npm的安装: 本地安装 1. 将安装包放在 ./node_modules 下(运行 npm 命令时所在的目录),如果没有 node_modules 目录,会在当前执行 npm ...
- asp.net mvc 各版本区别
MVC 6 ASP.NET MVC and Web API has been merged in to one. Dependency injection is inbuilt and part of ...
- SQL SERVER 数据库各版本功能对比
以前写了篇SQL SERVER 2008数据库各版本功能对比,官网提供的那个功能确实很好很强大,后面发现那个链接失效了.今天又遇到要对比SQL Server 2014数据库版本功能需求,搜索找了好久才 ...
- Python:版本升级
Linux 上安装的python版本是2.6.6,不能满足我运行软件的要求,所以对python进行升级.现在要了解MySQL Fabric,需要使用Python 2.7,所以只能对现有版本进行升级了. ...
- MySQL 索引
MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果合理的设计且使用索引的MySQL是一辆兰博基尼的话,那么没有设计和使用索引的MySQL就是 ...
- 浏览器js与css文件有缓存未更新致最新版本
这是由于编码人员频繁更改引入的资源文件,浏览器中存在缓存,当你清空浏览器缓存也无济于事时可以采用在资源文件尾部加?_MM(MM为随机参数)即可强制更新资源文件.
- 理解Java对象序列化
http://www.blogjava.net/jiangshachina/archive/2012/02/13/369898.html 1. 什么是Java对象序列化 Java平台允许我们在内存中创 ...
- Intel 推出 DPDK 开发包的意义是什么?
Intel 推出 DPDK 开发包的意义是什么? http://www.zhihu.com/question/27413080?sort=created 基于intel dpdk的包处理器,相较于基于 ...