HDU 5672:String【模拟】
来源:互联网 发布:乐高机器人的所有编程 编辑:程序博客网 时间:2024/06/06 06:35
String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 892 Accepted Submission(s): 289
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醉了,G++超时,C++过了。。。。AC-code:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){int T,k,len,i,j,kk,vis[27];long long sum;char str[1000005];scanf("%d",&T);while(T--){cin>>str;cin>>k;len=strlen(str);if(k==1){cout<<(long long)(len+1)*len/2<<endl;continue;}kk=0;sum=0;memset(vis,0,sizeof(vis));j=0;for(i=0;i<len;i++){if(!vis[str[i]-'a'])kk++;vis[str[i]-'a']++;while(kk>=k){sum+=len-i;vis[str[j]-'a']--;if(!vis[str[j]-'a']){kk--;j++;break;}j++;}}cout<<sum<<endl;}return 0; }
0 0
- HDU 5672:String【模拟】
- HDU-5672-String(模拟/追赶)
- hdoj 5672 String 【模拟】
- hdu 5202 Rikka with string(模拟)
- HDU 1708 Fibonacci String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- hdu 5672 String(BC——查找子串的个数 模拟)
- hdu 5672 Strings 模拟
- hdu 5672 String
- HDU 5672 String
- hdu 5672 String
- HDU 5672 String
- 贪心,模拟,构造(HDU 5414,CRB and String)
- HDU 1039 Easier Done Than Said?(String模拟)
- 模拟String
- hdu 5672 尺取法模拟
- string string string HDU
- hdu 5665 Lucky(简单题)(bestcoder#80 1000)
- 下载网页上的各种视频只需四步
- dp 16
- mysql数据库导入导出
- 实现带记忆功能的AutoCompleteTextView
- HDU 5672:String【模拟】
- 易语言学习第二十五课----CE查找内存
- HashMap实现原理分析
- 产品战略和战术
- MySQL操作命令及运算符
- 自己写一个ajax
- bzoj3295[Cqoi2011]动态逆序对(cdq分治||可持久化线段树)
- 20 Top Things to do after installing Fedora 23
- Android TextView中字体行间距的设置