hdu----(5056)Boring count(贪心)
Boring count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 228 Accepted Submission(s): 90
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.
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
abc
1
abcabc
1
abcabc
2
15
21
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=;
char str[maxn];
int sac[];
int main()
{
int cas,st,pos,k;
scanf("%d",&cas);
while(cas--)
{
memset(sac,,sizeof(sac));
scanf("%s %d",str,&k);
__int64 ans=;
st=;
for(int i=;str[i]!='\0';i++)
{
pos=str[i]-'a';
sac[pos]++;
if(sac[pos]>k)
{
while(str[st]!=str[i])
{
sac[str[st]-'a']--;
st++;
}
sac[str[st]-'a']--;
st++;
}
ans+=(i-st+);
}
printf("%I64d\n",ans);
}
return ;
}
hdu----(5056)Boring count(贪心)的更多相关文章
- HDU 5056 Boring count(不超过k个字符的子串个数)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 5056 Boring count
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...
- HDU 5056 Boring count(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5056 Problem Description You are given a string S con ...
- HDU 5056 Boring Count --统计
题解见官方题解,我这里只实现一下,其实官方题解好像有一点问题诶,比如 while( str[startPos] != str[i+1] ) cnt[str[startPos]]--, startPos ...
- hdu 5056 Boring count (窗体滑动)
You are given a string S consisting of lowercase letters, and your task is counting the number of su ...
- hdu 5056 Boring count (类似单调队列的做法。。)
给一个由小写字母构成的字符串S,问有多少个子串满足:在这个子串中每个字母的个数都不超过K. 数据范围: 1<=T<= 1001 <= the length of S <= 10 ...
- hdu Boring count(BestCode round #11)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Boring count(字符串处理)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
随机推荐
- Threads in Spring
使用Spring时经常会问,我们定义的Bean应该是Singleton还是Prototype?多个客户端同时调用Dao层,需要考虑线程安全吗?通过阅读官方文档和Spring的源代码,这类问题的答案是: ...
- PythonOCC 3D图形库学习—导入STEP模型
PythonOCC comes with importers/exporters for the most commonly used standard data files format in en ...
- Using Post_Query Trigger in Oracle Forms
When a query is open in the block, the Post-Query trigger fires each time Form Builder fetches a rec ...
- javascript 中函数eval()
eval()函数可以把一个字符串当作一个JavaScript表达式一样去执行它. 我们常常在Javascript中间到Eval这个函数, 有些人觉得这个函数很奇怪,可以把一些字符串变的功能很强大 在我 ...
- Java构建工具:如何用Maven,Gradle和Ant+Ivy进行依赖管理
原文来自:https://zeroturnaround.com/rebellabs/java-build-tools-how-dependency-management-works-with-mave ...
- ABAP WRITE、WRITE TO、FORMAT语句
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- jpg 批量压缩工具 v1.0
工作需要经常压缩大量图片,网上搜了一些 使用起来总觉得不方便.昨天自己用AIR 写了一个,功能简单,需要的朋友可以自己 下载使用win 版绿色版 http://pan.baidu.com/s/1k ...
- 移动端 移动web屏幕适配方案 随不同宽度的屏幕而改变
链接地址1:http://www.cnblogs.com/zjzhome/p/4802157.html 链接地址2:http://www.html-js.com/article/Mobile-term ...
- Python学习笔记4—列表
列表定义 >>> a=['] >>> type(a) <type 'list'> >>> bool(a) #列表有值,则为true T ...
- extern 关键字
1 http://baike.baidu.com/view/963932.htm?fr=ala0_1_1 extern可置于变量或者函数前,以表示变量或者函数的定义在别的文件中,提示编译器遇到此变量和 ...