HDOJ 5806 NanoApe Loves Sequence Ⅱ
来源:互联网 发布:开淘宝店收益怎么样 编辑:程序博客网 时间:2024/05/17 07:53
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5806
作为HDU集训队的一员,我很清楚Claris是一位数据结构大师,但正是如此,比赛的时候小编老是往数据结构上去想,哎,然而此题完全不用(=.= GG),只需要用到双指针就能够解决。
仔细思考,我们是要区间里面第k大的数大于m,那么其实只要区间里面有k个大于m的数就可以了,接下来就只需要用到双指针就行了。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 200000+5;typedef long long LL;int a[maxn];int main(){int T;scanf("%d", &T);while(T--){int n,m,k;scanf("%d%d%d", &n, &m, &k);for(int i=0; i<n; i++){int tmp;scanf("%d", &tmp);a[i] = (tmp >= m);}LL L,R,sum,ans;L = R = sum = ans = 0;sum = a[0];while(R < n){if(sum == k){ans += n-R;sum -= a[L];L++;}else{R++;sum += a[R];}}printf("%I64d\n", ans);}}
1 0
- hdoj5805 NanoApe Loves Sequence && hdoj 5806 NanoApe Loves Sequence Ⅱ
- HDOJ 5806 NanoApe Loves Sequence Ⅱ
- hdoj-5806-NanoApe Loves Sequence Ⅱ
- hdoj-5805-NanoApe Loves Sequence
- NanoApe Loves Sequence Ⅱ
- NanoApe Loves Sequence Ⅱ
- hdu 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- hdu 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806:NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 - NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- hdoj 5805 NanoApe Loves Sequence(模拟)
- HDU 5806 NanoApe Loves Sequence
- hdu NanoApe Loves Sequence Ⅱ
- PhoneWindowManager总结
- 《UNIX环境高级编程》四文件和目录读书笔记
- STM32之SPI_FLASH(实例)
- 257.[Leetcode]Binary Tree Paths
- Git之删除文件学习教程
- HDOJ 5806 NanoApe Loves Sequence Ⅱ
- 数据分布不均匀走HASH JOIN导致的性能问题
- Tomcat源码阅读之实例化Container
- Muduo库的框架剖析及总结(三)
- LINUX下的硬盘管理
- 设计模式GOF23——外观模式
- 接口数据的缓存及Linux定时缓存数据
- 【一天一道Leetcode】#203.Remove Linked List Elements
- 【算法】(扩展)KMP+manacher