题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5056

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
 
Output
For each case, output a line contains the answer.
 
Sample Input
3
abc
1
abcabc
1
abcabc
2
 
Sample Output
6
15
21
 
Source


官方题解:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjg2MDA2Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">


代码例如以下:
#include <cstdio>
#include <cstring>
const int maxn = 100017;
int main()
{
int t;
char str[maxn];
int st[27];
int k;
scanf("%d",&t);
while(t--)
{
memset(st,0,sizeof(st));
scanf("%s",str);
scanf("%d",&k);
__int64 ans = 0;
int len = strlen(str);
int startpos = 0;
for(int i = 0; i < len; i++)
{
int tt = str[i] -'a';
st[tt]++;
if(st[tt] > k)
{
while(str[startpos]!=str[i])
{
st[str[startpos]-'a']--;
startpos++;
}
st[str[startpos]-'a']--;
startpos++;
}
ans+=i-startpos+1;
}
printf("%I64d\n",ans);
}
return 0;
}

HDU 5056 Boring count(数学)的更多相关文章

  1. HDU 5056 Boring count(不超过k个字符的子串个数)

    Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. hdu 5056 Boring count

    贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...

  3. HDU 5056 Boring Count --统计

    题解见官方题解,我这里只实现一下,其实官方题解好像有一点问题诶,比如 while( str[startPos] != str[i+1] ) cnt[str[startPos]]--, startPos ...

  4. hdu 5056 Boring count (窗体滑动)

    You are given a string S consisting of lowercase letters, and your task is counting the number of su ...

  5. hdu 5056 Boring count (类似单调队列的做法。。)

    给一个由小写字母构成的字符串S,问有多少个子串满足:在这个子串中每个字母的个数都不超过K. 数据范围: 1<=T<= 1001 <= the length of S <= 10 ...

  6. hdu Boring count(BestCode round #11)

    Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  7. Boring count(字符串处理)

    Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. hdu----(5056)Boring count(贪心)

    Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. hdu 4961 Boring Sum(高效)

    pid=4961" target="_blank" style="">题目链接:hdu 4961 Boring Sum 题目大意:给定ai数组; ...

随机推荐

  1. SQL游标的使用与语法

    原文发布时间为:2010-08-07 -- 来源于本人的百度文章 [由搬家工具导入] 以[master].[dbo].[spt_values] 这个表为例子===declare @name nvarc ...

  2. 长沙理工校赛I题题解-连续区间的最大公约数

    题目来源https://www.nowcoder.com/acm/contest/96/I 解题前们需要先知道几个结论: 首先,gcd是有区单调性的: gcd(L,R)>=gcd(L,R+d)  ...

  3. 从无序序列中求这个序列排序后邻点间最大差值的O(n)算法

    标题可能比较绕口,简单点说就是给你一个无序数列A={a1,a2,a3……an},如果你把这个序列排序后变成序列B,求序列B中相邻两个元素之间相差数值的最大值. 注意:序列A的元素的大小在[1,2^31 ...

  4. Windows开发

    1. 介绍 这里简单介绍了Windows应用程序开发的基础知识 2. 基础 Windows下的应用程序有控制台程序和Win32窗口程序,这里讲的是Win32窗口程序 Windows提供了相关静态库(L ...

  5. linux2.4内核调度

    进程调度需要兼顾3种进程:交互进程,批处理进程,实时进程,在设计一个进程调度机制时需要考虑具体问题 (1)调度时机? 答:进程在用户空间可以pause()或者让内核设置进程为睡眠状态,以此调度,调度还 ...

  6. jenkins下脚本权限问题

    在jenkins环境下,执行需要root权限的脚本,报错. 修改方法: 1. centos环境下,在/etc/sudoers.d/ 目录下,增加一个 jenkins文件,内容如下: Defaults: ...

  7. IE/FF/Chrome下document.documentElement和document.body的 scrollHeight/scrollTop/clientHeight 以及判断滚动条是否已拉到页面最底部

    DTD已声明 IE document.documentElement.scrollHeight 浏览器所有内容高度 ,document.body.scrollHeight 浏览器所有内容高度 docu ...

  8. dubbo框架的简单介绍

    以下的官网的介绍. dubbo是SOA.小例子是简单的远程调用(生产者消费者的模式出现).http://blog.csdn.net/huangyekan/article/details/4217267 ...

  9. 2016集训测试赛(二十)Problem B: 字典树

    题目大意 你们自己感受一下原题的画风... 我怀疑出题人当年就是语文爆零的 下面复述一下出题人的意思: 操作1: 给你一个点集, 要你在trie上找到所有这样的点, 满足点集中存在某个点所表示的字符串 ...

  10. 2016北京集训测试赛(十七)Problem B: 银河战舰

    Solution 好题, 又是长链剖分2333 考虑怎么统计答案, 我场上的思路是统计以一个点作为结尾的最长上升链, 但这显然是很难处理的. 正解的方法是统计以每个点作为折弯点的最长上升链. 具体的内 ...