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. resume 简历

    1:uestc社会实践平台,sql,mapper.xml,,图片验证码,读写excel,excel和list,数据库的转化. 2:购物网站,全代码,平台搭建,服务发布,远程数据库连接,前端,搜索,支付 ...

  2. [py]函数中yield多次返回,延迟计算特性-杨辉三角

    搞清什么是杨辉三角 每行是一个数组, 第一行: [1] 第二行: [1, 1] 第三行: [1, 2, 2, 1] ... 画的好看点就是,不过没啥卵用 1 / \ 1 1 / \ / \ 1 2 1 ...

  3. error.jsp错误页面跳转,统一异常处理

    常见web项目中会用倒计时然后跳转页面来处理异常 error.jsp关键代码: <script language="javascript" type="text/j ...

  4. HTML <input> 标签的 name 属性

    定义和用法 name 属性规定 input 元素的名称. name 属性用于对提交到服务器后的表单数据进行标识,或者在客户端通过 JavaScript 引用表单数据. 注释:只有设置了 name 属性 ...

  5. [LeetCode] 529. Minesweeper_ Medium_ tag: BFS

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  6. Twitter OA prepare: Anagram is A Palindrome

    Algorithm: Count the number of occurrence of each character. Only one character with odd occurrence ...

  7. canvas实现验证码功能

    我们在做一些后台系统登录功能的时候,一般都会用到验证码,最多的就是后台生成的验证码图片返回给前端的.也可以不调用后端接口,前端使用canvas直接生成验证码. 由于功能过于简单,不需要多少代码和文字说 ...

  8. EPD的驱动

    整个e-ink技术的生产流程:1997年从MIT媒体实验室走出来的E-INK公司成立并专注于研发具有良好阅读体验的电子纸.其中最著名的产品就是Vizplex 电子墨水.E-INK提供电子墨水给Pane ...

  9. 禁止F12与右键

    实践项目的代码哦,给大家分享下,如何屏蔽右键与F12. 应用网站  www.empiretreasure.vip   与       www.MineBook.vip.可以去逛逛哦. 不多说了,上代码 ...

  10. java文件生成

    package com.gcy.test.util; import java.io.BufferedWriter; import java.io.File; import java.io.FileNo ...