Boring count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 928 Accepted Submission(s): 381
Problem Description
You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.
Input
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.
[Technical Specification]
1<=T<= 100
1 <= the length of S <= 100000
1 <= K <= 100000
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.
[Technical Specification]
1<=T<= 100
1 <= the length of S <= 100000
1 <= K <= 100000
Output
For each case, output a line contains the answer.
Sample Input
3 abc 1 abcabc 1 abcabc 2
Sample Output
6 15 21
题意:出现字母不能超过k次的串的个数
///AC代码
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;
const int maxn = 100010;
char str[maxn];
int vis[30];
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int k;
scanf("%s", str);
scanf("%d", &k);
memset(vis, 0, sizeof(vis));
int len = strlen(str);
int ans = 0;
ll sum = 0;
for (int i = 0; i < len; i++)
{
vis[str[i] - 'a']++;
while (vis[str[i] - 'a'] > k)
{
vis[str[ans] - 'a']--;
ans++;
}
sum += (i - ans + 1);
}
printf("%I64d\n", sum);
}
return 0;
}