hdu 5672 String (尺取法)
来源:互联网 发布:百度鹰眼定位软件 编辑:程序博客网 时间:2024/04/30 02:11
String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1961 Accepted Submission(s): 636
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 leastk(1≤k≤26) distinct characters?
How many substrings there are that contain at least
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 stringS .
The second line contains a integerk(1≤k≤26) .
The first line contains string
The second line contains a integer
Output
For each test case, output the number of substrings that contain at least k dictinct characters.
Sample Input
2abcabcabca4abcabcabcabc3
Sample Output
055
Source
BestCoder Round #81 (div.2)
Recommend
wange2014 | We have carefully selected several similar problems for you: 6055 6054 6053 6052 6051
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;char s[1000333];int c[30];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%s",s); memset(c,0,sizeof(c)); int len=strlen(s); int l = 0,r = 0,k; long long ans=0; scanf("%d",&k); int cnt=0; while(l<=r&&l<len) { while(cnt<k&&r<len) { c[s[r]-'a']++; if(c[s[r]-'a']==1)cnt++; r++; } if(cnt==k)ans+=len-r+1; if(c[s[l]-'a']==1) cnt--; c[s[l]-'a']--; l++; } printf("%lld\n",ans); }}
阅读全文
0 0
- HDU 5672 String【尺取法】
- hdu 5672 String【尺取法】
- HDU 5672 String (尺取法)
- HDU 5672 String(尺取法)
- hdu 5672 String (尺取法)
- HDU 5672 String(尺取法)
- hdu 5672(尺取法)
- hdu 5672(尺取法)
- hdu 5672 尺取法模拟
- 尺取法求解HDU 5672
- HDU 5672 String(尺取法)——BestCoder Round #81(div.1 div.2)
- [hdu 5672][BestCoder Round #81 t3] String 尺取法||双指针法
- hdoj 5672 String (尺取法)
- hdu5672 String(尺取法)
- hdu5672 string(尺取法)
- hdu 1937(尺取法)
- hdu 5056(尺取法)
- hdu 5178(尺取法)
- BroadcastReceiver Hook
- Sublime Text3 如何安装、删除及更新插件
- H
- java:字符型数组转换为字符串;字符串转换为字符型数组
- 欢迎使用CSDN-markdown编辑器
- hdu 5672 String (尺取法)
- git(六)-标签与diff
- HTTPS和HTTP的区别
- java线程池
- Hdu2511汉诺塔X
- java IO流总结
- Android性能优化(View篇)
- hdu 6035 树分治
- 用python+numpy+matplotalib实现梯度下降法