hdu 5672 String 尺取法
String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
How many substrings there are that contain at least k(1≤k≤26) distinct characters?
The first line contains string S.
The second line contains a integer k(1≤k≤26).
abcabcabca
4
abcabcabcabc
3
55
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#define true ture
#define false flase
using namespace std;
#define ll __int64
#define inf 0xfffffff
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int flag[];
char a[];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
while(x--)
{
memset(flag,,sizeof(flag));
scanf("%s",a);
scanf("%d",&y);
int st=,en=,ji=;
ll ans=;
int len=strlen(a);
while()
{
while(en<len&&ji<y)
{
if(flag[a[en]-'a']==)
ji++;
flag[a[en]-'a']++;
en++;
}
if(ji<y)break;
ans+=(len-en+);
flag[a[st]-'a']--;
if(flag[a[st]-'a']==)
ji--;
st++;
}
printf("%I64d\n",ans);
}
return ;
}
hdu 5672 String 尺取法的更多相关文章
- HDU 5672 String 尺取法追赶法
String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...
- HDU 5672 String【尺取法】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5672 题意: 有一个10≤长度≤1,000,000的字符串,仅由小写字母构成.求有多少个子串,包含有 ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- HDU 5672 String 【尺取】
<题目链接> 题目大意:给定一个只由26个小写字母组成的字符串,现在问你至少包含k个不同字母的连续子序列总数有多少. 解题分析:经仔细研究,我们发现,每次尺取到符合要求的最小区间,然后将区 ...
- HDU 5672 String
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5672 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)
题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...
- hdu 5510 Bazinga KMP+尺取法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标( ...
- Vasya and String(尺取法)
Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- HDU 6103 Kirinriki(尺取法)
http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...
随机推荐
- myeclipse maven工程调试调试
1:使用了maven带的tomca插件进行启动.下面讲一下如何进行调试程序 2:在程序中打断点 3:选择>debug>debug configuration 在goals处添加启动命令 4 ...
- [py]str list切片-去除字符串首尾空格-递归思想
取出arr的前几项 #方法1 print([arr[0], arr[1]]) #方法2 arr2 = [] for i in range(2): arr2.append(arr[i]) print(a ...
- 蒙特卡罗(Monte Carlo)方法简介
蒙特卡罗(Monte Carlo)方法,也称为计算机随机模拟方法,是一种基于"随机数"的计算方法. 二 解决问题的基本思路 Monte Carlo方法的基本思想很早以前就被人们所发 ...
- 从 Zero 到 Hero ,一文掌握 Python
译文:开源中国 www.oschina.net/translate/learning-python-from-zero-to-hero 第一个问题,什么是 Python ?根据 Python 之父 G ...
- Log4net 乱码问题解决
在将log4net输出到UdpAppender会出现乱码问题,当然,丢到第三方日志分析工具glaylog下,也出现中文乱码. <?xml version="1.0"?> ...
- 1.0ARM体系结构-ARM体系结构
对ARMcpu有整体而专业的认识. ARM只是设计arm核,而不生产. ARM 掌握的是标准.
- MySQL从删库到跑路_高级(三)——视图
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.视图简介 1.视图简介 视图是由SELECT查询语句所定义的一个虚拟表,是查看数据的一种非常有效的方式.视图包含 ...
- SpringBoot之集成WebSocket
websocket是什么不做介绍.开发环境:jdk1.8,win7_64旗舰版,idea 1.初始化一个springboot项目 2.加入websocket依赖 <!-- springb ...
- Django框架----render函数和redirect函数的区别
render函数和redirect函数的区别: render:只会返回页面内容,但是未发送第二次请求 redirect:发挥了第二次请求,url更新 具体实例说明 render: redirect:
- TED #09# You don't have to be an expert to solve big problems
Tapiwa Chiwewe: You don't have to be an expert to solve big problems Collection noticed a haze hangi ...