题干:

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

题目大意:

找出字符串中所有字母出现次数不超过k次的子串数量

解题报告:

尺取就可以了。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;char a[100000 + 5];
int bk[40];
int k;
ll ans;
int main()
{
//  freopen("in4.txt","r",stdin);int t,l,r,len;cin>>t;while(t--) {memset(bk,0,sizeof(bk) );ans = 0;  scanf("%s",a);scanf("%d",&k);len = strlen(a);l=r=0;while(r<len) {bk[a[r]-'a']++;while(bk[ a[r] - 'a' ] > k) {//注意这是while不是ifbk[ a[l] - 'a']--;l++;}
//          printf("%lld  %d  %d  \n",ans,l,r);ans+=r-l+1;r++; }printf("%lld\n",ans);}
/**     //以左端点 while(r<len) {if(l == r) {r++;}}//后续处理 while(l<=r) {}
*/      return 0 ;
}

【HDU - 5056】Boring count (尺取法)相关推荐

  1. 解题报告 (十三) 尺取法

    文章目录 尺取法 解题报告 PKU 2100 Graveyard Design PKU 3061 Subsequence PKU 2739 Sum of Consecutive Prime Numbe ...

  2. Codeforces 1548B Integers Have Friends 尺取法 Hdu 7073 Integers Have Friends 2.0 力能扛鼎随机算法

    文章目录 题意 题解 CF1548B 题解 Hdu 7073 CF1548B HDU7073 题意 定义数的好友组为一个集合SSS,取正整数m>1,∀x∈s,xmodmm>1,\foral ...

  3. hdu 5178(尺取法)

    pairs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem De ...

  4. hdu 1937(尺取法)

    题意:给定一个R*C的矩阵,选择一个面积最小的子矩阵,使得其内部'.'的个数>=k. 解题思路:这道题如果时普通的枚举,会要达到O(N^5)严重超时.这里可以采用高效的枚举方法--尺取法. 首先 ...

  5. hdu 5358(尺取法)

    解题思路:这题可以利用尺取法,不过需要两个指针.如果采用一个指针,会出现这种情况,由于是取对数,所以中间可能会有很多log2S(i,j)的值相等,如果只有一个指针,会使得一些区间没有被算进去.比如0, ...

  6. hdu 5672(尺取法)

    题意:有一个10<=长度<=1000000的字符串,仅由小写字母组成.求有多少子串,包含至少k(1<= k <= 26)个不同的字母. 解题思路:利用尺取法求符合条件的临界区间 ...

  7. 【HDU - 5672】String(尺取法)

    题干: There is a string SS.SS only contain lower case English character.(10≤length(S)≤1,000,000)(10≤le ...

  8. poj2739(尺取法+质数筛)

    题意:给你一个数,问这个数能否等于一系列连续的质数的和: 解题思路:质数筛打出质数表:然后就是尺取法解决: 代码: #include<iostream> #include<algor ...

  9. poj_2739 尺取法

    题目大意 给定一个数字N,N可能由1个或多个连续的素数求和得到,比如41 = 2+3+5+7+11+13, 41 = 11+13+17, 41 = 41.求出对于N,所有可能的组合形式. 题目分析 先 ...

  10. 算法篇之-----滑动窗口(尺取法)

    滑动窗口(尺取法 1. 介绍 2. 滑动窗口法的大体框架 4.最小覆盖子串 5.窗口数量 6.最小值 1. 介绍 滑动窗口法,也叫尺取法(可能也不一定相等,大概就是这样 =.=),可以用来解决一些查找 ...

最新文章

  1. 网络编程学习笔记(getaddrinfo函数)
  2. Android高效编程注意事项
  3. 31岁博士副县长拟提任正处,3年前毕业被人才引进
  4. Python 代码优化常见技巧
  5. python django图书管理系统_Python框架:Django写图书管理系统(LMS)
  6. Python爬虫_乱码、转码
  7. Bailian3253 集合的划分【递归】
  8. 解决docker-compose: command not found
  9. 脚本都不写,不能算正式测试
  10. [USACO DEC13] 名称记录
  11. latex数学符号加粗_latex 数学符号加粗
  12. qq空间相册查看器_python爬虫抓取QQ空间相册中的照片和视频
  13. html闹钟设置,闹钟设置页.html
  14. Gromacs基础教程一:入门建议
  15. 我国嵌入式技术及应用现状分析
  16. 2021--ICPC网络预选第一场--A Busiest Computing Nodes
  17. 必收藏的实用网站(一)
  18. 键盘计算机论文,计算机论文
  19. 中国平安增持华夏幸福5.69%股权 看好长期战略协同
  20. 【C语言】scanf函数格式控制符

热门文章

  1. java 打印 模板_Java输入输出模板
  2. win10进程太多怎么优化_用过最好用的Win10优化软件,全方面优化和管理!
  3. oracle 12c缩容磁盘组,oracle 表收缩
  4. python筛选法求素数讲解_埃氏筛选法求素数 Python
  5. 保存到数据库乱码mysql_Linux下MySQL保存进去数据为乱码的解决办法
  6. 2.5d generator 2.0_ps插件【2.5D插件】
  7. 大连理工优化方法matlab,大连理工大学2016年秋季优化方法大作业.pdf
  8. mysql group by 慢_mysql“group by”查询非常慢
  9. hssfcolor 不建议使用_不建议使用微信双开的真正原因!
  10. 【Direct3D游戏开发】——DirectInput 让世界动起来