Test instructions: Given the number of N, T, C, and N, ask how many consecutive C numbers you have in this n number, and the number of C is not much more than T.
Analysis: Very simple, is a sliding window, from the first start to traverse, if you find the number of C, then let the interval front-end point plus 1, if not found, then the interval front-end is equal to the posterior interval of +1.
The code is as follows:
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int MAXN = 2e5 + 15;const int INF = 0x3f3f3f3 F;int A[maxn];int Main () { int n, t, C; while (CIN >> n >> T >> c) { for (int i = 0; i < n; ++i) scanf ("%d", &a[i]); int s = 0, E = 0; int cnt = 0; int ans = 0; while (e < n) { while (A[e] <= t && CNT < c && E < n) ++cnt, ++e; if (cnt = = c) { --cnt; ++ans; } else{ ++e; CNT = 0; } } cout << ans << endl; } return 0;}
Codeforces 427B Prison Transfer