HDU 5056 Boring Count
HDU_5056
描述
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.
输入格式
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, output a line contains the answer.
样例
输入
3
abc
1
abcabc
1
abcabc
2
输出
6
15
21
思路
i,j表示最大不冲突字串的首和尾。
用26个队列来存26个字母的位置,当某个队列的size大于k时,明显冲突。计算i-j之间的子串的个数。要注意算重的部分,要减去。
i更新为对应队列里front的值。特别注意的是,位置在old_i和new_i之间的字母的队列要pop掉,这个BUG卡了我两个小时,OMG…………
代码很简约,也比较易懂。
c++代码
|
|