HDOJ 5806 NanoApe Loves Sequence Ⅱ
2016-08-06 22:03
267 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5806
![](http://img.blog.csdn.net/20160806215942718)
作为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);
}
}
作为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);
}
}
相关文章推荐
- hdoj5805 NanoApe Loves Sequence && hdoj 5806 NanoApe Loves Sequence Ⅱ
- hdoj-5806-NanoApe Loves Sequence Ⅱ
- hdoj5806 NanoApe Loves Sequence Ⅱ(尺取法)
- BC#86.1003(HDOJ5806)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 Ⅱ(尺取法)
- 二指针_____NanoApe Loves Sequence II(hdu 5806 BestCoder Round #86)
- HDU-5806-NanoApeLovesSequenceⅡ(尺取法)
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取)
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- BestCoder Round #86 1003 &HDU 5806——NanoApe Loves Sequence Ⅱ
- hdoj-5805-NanoApe Loves Sequence
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)