题意:
n个囚犯站成一排,每个囚犯都有一个危害值代表其危害程度,现要连续运输c个囚犯到其他监狱,要求这c个囚犯的危害值均
n个囚犯站成一排,每个囚犯都有一个危害值代表其危害程度,现要连续运输c个囚犯到其他监狱,要求这c个囚犯的危害值均
小于t,求一共有多少种选法。
输入:
4 3 3 2 3 1 1
1 1 1 2
11 4 2 2 2 0 7 3 2 2 4 9 1 4
输出:
2
0
6
分析:
统计伤害值不大于t 的罪犯的数量--num,如果num 大于连续运送的罪犯的数量c的时候,方案数+1。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
long long int a[maxn];
int main()
{
int n,t,c,num1=0,num2=0;
cin >>n>>t>>c;
for(int i=0; i<n; i++)
{
cin >>a[i];
if(a[i]>t)
num1=0;
else
num1++;
if(num1>=c)
num2++;
}
cout <<num2<<endl;
return 0;
}