[周赛] HDU-5056 Boring count
来源:互联网 发布:java ftp 文件排序 编辑:程序博客网 时间:2024/06/05 02:57
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
3abc1abcabc1abcabc2
Sample Output
61521
题意:输入一个字符串,找出重复字母个数不超过K个的字串的个数。
思路:使用的是双指针法也叫窗口移动或尺取法。定义两个指针,始终保持指针内的子串符合题目要求,向右移动右指针,若不符合要求,则将左指针向右移动直到指针内的子串符合题目要求为止。这样就求出了每个点向左延伸最远符合要求的点。一个长度为n的字符串它的字串个数为1+2+..+n。
#include <stdio.h>#include <string.h>char s[100010];int flag[100010];int main(){ int t,k,i; __int64 sum; scanf("%d%*c",&t); while(t--) { memset(flag,0,sizeof(flag)); sum=0; scanf("%s",s); scanf("%d",&k); int len=strlen(s),pos=0; for(i=0;i<len;i++) { flag[s[i]-'a']++; if(flag[s[i]-'a']>k) { while(s[pos]!=s[i]) { flag[s[pos]-'a']--; pos++; } flag[s[pos]-'a']--; pos++; } sum += i+1-pos; } printf("%I64d\n",sum); }
0 0
- [周赛] HDU-5056 Boring count
- HDU 5056 - Boring count
- hdu 5056Boring count
- hdu 5056 Boring count
- hdu 5056 Boring count
- HDU 5056Boring count
- HDU 5056 Boring Count --统计
- HDU-5056-Boring count-周赛4补题
- HDU 5056 Boring count(窗口滑动法)
- HDU 5056 Boring count(贪心)
- HDU 5056 Boring count(数学)
- hdu 5056 Boring count ( 窗口转移法)
- hdu 5056 Boring count (窗口滑动)
- hdu 5056 Boring count(尺取法)
- HDU 5056 Boring count(滑动窗口)
- HUD 5056 Boring count
- hdoj-5056-Boring count
- HDU 5056 Boring count 字符串处统计+滑动窗口法
- vsftpd配置文件详解
- VMP1.8的IAT分析,同时膜拜一下Nooby大牛
- AndroidAnnotations eclipse中代码无错 项目出现红叉无法调试编译
- java迭代器模式
- 简单搭建nodeJS服务,访问本地站点文件
- [周赛] HDU-5056 Boring count
- HDOJ 5137 How Many Maos Does the Guanxi Worth(最短路删点)
- netbeans 窗体字体大小设置
- Java运行时多态性:继承和接口的实现
- NSAttributedString编程
- spring mvc环境搭建demo
- SIFT相关参考资料
- android studio项目修改eclipse可以使用的项目
- 极小值极大值算法-井字棋