HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
2016-08-06 23:33
393 查看
NanoApe Loves Sequence Ⅱ
题目链接:点我打开链接[align=left]Source[/align]
BestCoder Round #86
题意:问你这个数列中有多少个区间里的第 k大的数不小于 m,大前提:这个区间必须至少要有 k 个数。
官方题解: 将不小于m的数看作1,剩下的数看作0,那么只要区间内1的个数不小于k则可行,枚举左端点,右端点可以通过two-pointer求出。 时间复杂度O(n)。二分也可以,双指针也可以。尺取法也可以。
AC代码:
//#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<map> #include<queue> #include<set> #include<stack> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 200000+10; int a ; int MAX[3]; int MAXN[3]; int read() { int v = 0, f = 1; char c =getchar(); while( c < 48 || 57 < c ){ if(c=='-') f = -1; c = getchar(); } while(48 <= c && c <= 57) v = v*10+c-48, c = getchar(); return v*f; } int main() { int t,n,m,k; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } int num=0, r=0 ; ll ans=0; for(int i=1;i<=n;i++){ while(num < k && r < n){ r++; /* if(a[r]>=m) num++; */ num += a[r]>=m; // printf("num=%d\n",num); // printf("a[r]=%d\n",a[r]); // printf("m=%d\n",m); } if(num < k) break; ans += n-r+1; num-= a[i]>=m; } printf("%lld\n",ans); } return 0; }
相关文章推荐
- Hdu-5806 NanoApe Loves Sequence(尺取法)
- hdu 5806 NanoApe Loves Sequence Ⅱ (尺取法)
- (尺取法)HDU - 5806 NanoApe Loves Sequence Ⅱ
- hdu 5806 NanoApe Loves Sequence Ⅱ(二分或尺取法)
- HDU-5806-NanoApeLovesSequenceⅡ(尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取法)
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 BestCoder Round #86 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 Ⅱ (BestCoder Round #86)
- HDU 5806 NanoApe Loves Sequence Ⅱ (滑动窗口 或者 二分法)
- BestCoder Round #86 1003 &HDU 5806——NanoApe Loves Sequence Ⅱ
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ(前缀和)
- hdu 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ
- HDU-5806-NanoApe Loves Sequence Ⅱ(水题)