HDU 5806 NanoApe Loves Sequence Ⅱ [尺取法]
来源:互联网 发布:win10磁盘优化有几遍 编辑:程序博客网 时间:2024/06/06 07:31
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=721&pid=1003
尺取法,先找k个>=m的,定位到r指针。然后移动l,如果a[l]>=m,说明现在区间内不足k个,r指针向后移,补到k个,如果a[l]
Code
#include <iostream>#include <cstdio>using namespace std;const int MAXN = 200000 + 9;int a[MAXN];void solve(){ int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } long long ans = 0; int r; int t = 0; for (r = 0; r < n; r++) { if (a[r] >= m) t++; if (t == k) break; } ans += (n - r); for (int l = 1; l < n; l++) { if (a[l - 1] >= m) { t--; r++; for (;r < n; r++) { if (a[r] >= m) t++; if (t == k) break; } if (r >= n) break; ans += (n - r); } else { ans += (n - r); } } cout << ans << endl;}int main(){ //freopen("in", "r", stdin); int t; scanf("%d", &t); while (t--) { solve(); }}
1 0
- 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 Ⅱ尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ 尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ(二分或尺取法)
- HDU 5806 · NanoApe Loves Sequence Ⅱ【尺取法】
- hdoj5806 NanoApe Loves Sequence Ⅱ(尺取法)
- NanoApe Loves Sequence Ⅱ(尺取法)
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU5806 NanoApe Loves Sequence Ⅱ(尺取法\two pointers)
- 跟我一起写Makefile(9)--- 书写命令(显示命令+命令执行+命令出错+嵌套执行make+定义命令包)
- 常用的linux命令-scp命令
- socketpair创建双向通信的管道(全双工通信)
- 数据结构实验之二叉树的建立与遍历
- 栈
- HDU 5806 NanoApe Loves Sequence Ⅱ [尺取法]
- Java-小白成长日记(2016年8月6日)
- ffmpeg命令详解(三)
- 数据结构之顺序表常用操作整理
- POJ 3746 Cyclic Nacklace(KMP)
- uva562 Dividing coins(背包)
- CTR预估算法小结
- HTML源码DOM的offsetLeft,Left,clientLeft区别是什么样的?如何理解?
- 大数据DTSpark"蘑菇云"行动之 第三课:IDE开发第一个Scala程序