码迷,mamicode.com
首页 > 其他好文 > 详细

【HDOJ】P5056 Boring count

时间:2014-09-29 23:39:31      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

题目意思是给你一个字符串和K,让你求其中有多少个字串中每个字母的出现次数不超过K次,可以等于

题目意思是很简单的,写起来也很简单,不过就是注意最后要是long long要不WA了,555~

bubuko.com,布布扣
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

char s[100005];
int n,cnt[30],k,T,st;
long long ans;

int main(){
    cin>>T;
    cin.get();
    while(T--){
        scanf("%s",s);
        scanf("%d",&k);
        memset(cnt,0,sizeof(cnt));
        ans=0;
        st=0;
        n=strlen(s);
        for (int i=0;i<n;i++){
            cnt[s[i]-a]++;
            while(cnt[s[i]-a]>k) cnt[s[st++]-a]--;
            ans+=i-st+1;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
View Code

 

【HDOJ】P5056 Boring count

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/XGHeaven/p/4001118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!