hdu5806 two-pointers
来源:互联网 发布:nginx sub filter 编辑:程序博客网 时间:2024/06/11 20:36
头尾两个指针扫就可以了,注意ans非常大,要用long long ,输入输出要配套
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int T,n,m,k,x,s,i,j;long long ans;int a[200010];int main(){ scanf("%d", &T); while (T--) { scanf("%d%d%d", &n, &m, &k); memset(a,sizeof(a),0); for (int i=1;i<=n;i++) { scanf("%d", &x); if (x>=m) a[i]=1; else a[i]=0; } ans=0; s=a[1];i=1;j=1; while (i<=j && j<=n) { if (s>=k) { ans+=(n-j+1); s-=a[i]; i++; } while (s<k && j<=n) {j++;s+=a[j];} } printf("%I64d\n", ans); }}
0 0
- hdu5806 two-pointers
- HDU5806 NanoApe Loves Sequence Ⅱ(尺取法\two pointers)
- Two Pointers
- Two pointers
- Two pointers
- HDU5806 NanoApe Loves Sequence Ⅱ BestCoder Round #86 two-pointer
- Poj 3320(two pointers)
- Poj 2566(two pointers)
- Sum( two pointers )
- Array Two Pointers 总结
- HDU-5289<two pointers>
- Odd Palindromes Two Pointers
- LeetCode--Two Pointers
- poj2566 Bound Found -- Two pointers
- Leetcode - Pointers/Array - Two sum
- Two pointers技巧的应用
- [leetcode][two pointers] 3Sum
- [leetcod][two pointers] 4Sum
- Codeforces Round #223 (Div. 2) E Sereja and Brackets
- POJ 3261Milk Patterns
- 通道和选区的关系
- linux minicom usb串口
- PHP.INI配置:Session配置详细说明
- hdu5806 two-pointers
- Delphi学习笔记(三)
- Makefile 使用总结(好文推荐)
- TortoiseSVN使用教程
- 用Go来编写分布式系统,相比用C/C++的好处
- STM32F10x_硬件I2C读写EEPROM(标准外设库版本)
- 从决策树学习谈到贝叶斯分类算法、EM、HMM
- 结构化数据与非结构化数据
- ZZuli oj 1895: 985的0-1串难题(二分+打表)