题目链接: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. 序列操作(bzoj 1858)

    Description lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 ...

  2. android开发过程遇到的一些错误

    Unable to resolve target "android-x" 这是工程的Android版本和本地SDK中的版本不一致,一般做下处理: 1. 右击项目->andro ...

  3. PE笔记之PE基本结构图(PE笔记索引)

    PE(Portable Execute) 文件是Windows下可执行文件的总称,常见的有DLL,EXE,OCX,SYS等,事实上,一个文件是否是PE文件与其扩展名无关,PE文件可以是任 何扩展名.那 ...

  4. NS5S1153 切換器

    昨天在研讀 NS5S1153 的 spec, 發現有一個詞 很陌生 DPDT, 原來是 double pole double throw 的縮寫,雙軸雙切, 更詳細的解釋可以看這個博客的另一篇 &qu ...

  5. spingboot 邮件模板发送;

    <!-- 邮件start --><dependency> <groupId>javax.mail</groupId> <artifactId> ...

  6. python脚本传递参数

    给python程序传递参数 运行python脚本时有时需要执行实传递参数 在linux下: [root@Test ~]# cat /opt/python.py #!/usr/local/bin/pyt ...

  7. Viewpager禁止滑动

    参考:http://www.jianshu.com/p/d3d766cf73d7 public class NoScrollViewPager extends ViewPager { private ...

  8. interview fb2

    2014.7.8fb #include <iostream> using namespace std; struct TreeNode{ int val; TreeNode *left; ...

  9. 无法启动Visual Studio的localhost web服务器,端口"xxxx"已被使用

    解决方法:项目属性-Web里面有web服务器端口的设置,换个端口即可.项目属性->web->服务器,不要选择“自动分配端口”,选择“使用指定端口”,后面输入一个端口号

  10. idea---搭建maven,tomcat入门

    这篇随笔讲讲idea工具的安装和使用和在idea中搭建maven的分享. 一.概念 1.IntelliJ IDEA是什么? DEA 全称 IntelliJ IDEA,是java编程语言开发的集成环境. ...