String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
There is a string S.S only contain lower case English character.(10≤length(S)≤1,000,000)
How many substrings there are that contain at least k(1≤k≤26) distinct characters?
 
Input
There are multiple test cases. The first line of input contains an integer T(1≤T≤10) indicating the number of test cases. For each test case:

The first line contains string S.
The second line contains a integer k(1≤k≤26).

 
Output
For each test case, output the number of substrings that contain at least k dictinct characters.
 
Sample Input
2
abcabcabca
4
abcabcabcabc
3
 
Sample Output
0
55
 
Source
思路:就是从左端点找到最近的那个符合条件的右端点;这题特容易超时
尺取法:http://wenku.baidu.com/link?url=_jFXiTHG4ZN60Ki0U5Svb26oKLbbUMtJAwrSnkDC1W1e9RqFK_DaolSUE3MyCKmrv2oGEKWn_GN5P7IQuV0Qp5jxA1SApZHSBYI4NqEYq_u
#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 尺取法的更多相关文章

  1. HDU 5672 String 尺取法追赶法

    String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...

  2. HDU 5672 String【尺取法】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5672 题意: 有一个10≤长度≤1,000,000的字符串,仅由小写字母构成.求有多少个子串,包含有 ...

  3. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  4. HDU 5672 String 【尺取】

    <题目链接> 题目大意:给定一个只由26个小写字母组成的字符串,现在问你至少包含k个不同字母的连续子序列总数有多少. 解题分析:经仔细研究,我们发现,每次尺取到符合要求的最小区间,然后将区 ...

  5. HDU 5672 String

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5672 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  6. HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)

    题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...

  7. hdu 5510 Bazinga KMP+尺取法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标( ...

  8. Vasya and String(尺取法)

    Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. HDU 6103 Kirinriki(尺取法)

    http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...

随机推荐

  1. [vue]js模块导入导出export default

    webstrom调试未授权问题解决 分es6语法和node语法 参考 参考 - export default s1 1.仅能出现1次default 2.导入时候可以随便命名 3,导出时候不必写{} - ...

  2. 【Cocos2dx 3.3 Lua】导出Cocos2dx API文档

    一.Doxygen导出Cocos2dx html doc              1.1 打开Doxygen软件,选择 File-->Open打开Cocos2dx docs目录下的doxyge ...

  3. Java序列化总结

    什么是序列化? 序列化是将对象的状态信息转化为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后可以通过存储区中读取或反序列化对象的状态重新创建对象. 为什么要序 ...

  4. [LeetCode] 104. Maximum Depth of Binary Tree_Easy tag: DFS

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. linux命令:文件搜索命令

    ---恢复内容开始--- 文件搜索命令:which 命令名称:which 命令所在路径:/usr/bin/which 执行权限:所有用户 语法:which  [命令名称] 功能描述:显示系统命令所在目 ...

  6. mvc actionresult返回各种文件

    public ActionResult ReviewFile(string folderName, string fileBasename, string extendName) { //以后根据后缀 ...

  7. html lang属性

    HTML 的 lang 属性可用于网页或部分网页的语言.这对搜索引擎和浏览器是有帮助的. 根据 W3C 推荐标准,您应该通过 <html> 标签中的 lang 属性对每张页面中的主要语言进 ...

  8. Ubuntu16.04 +cuda8.0+cudnn+caffe+theano+tensorflow配置明细

      本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www ...

  9. Java设计模式应用——策略模式

    对于相同类型相同类型的输入输出,在不同场景下需要使用不同的逻辑处理,则可以使用策略模式. 比如排序算法有堆排序,快速排序,冒泡排序,选择排序等.为了保证排序效率,需要在不同场景下选择不同排序算法,这时 ...

  10. Python之路----递归函数

    1.小练一下 用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb name=['alex','wupeiqi','yuanhao','nezha'] # def func(item ...