日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5056】Boring count (尺取法)

發(fā)布時(shí)間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5056】Boring count (尺取法) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.

Input

In the first line there is an integer T , indicates the number of test cases.?
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.?

[Technical Specification]?
1<=T<= 100?
1 <= the length of S <= 100000?
1 <= K <= 100000

Output

For each case, output a line contains the answer.

Sample Input

3 abc 1 abcabc 1 abcabc 2

Sample Output

6 15 21

題目大意:

找出字符串中所有字母出現(xiàn)次數(shù)不超過(guò)k次的子串?dāng)?shù)量

解題報(bào)告:

? ? 尺取就可以了。

AC代碼:

#include<bits/stdc++.h> #define ll long long using namespace std;char a[100000 + 5]; int bk[40]; int k; ll ans; int main() { // freopen("in4.txt","r",stdin);int t,l,r,len;cin>>t;while(t--) {memset(bk,0,sizeof(bk) );ans = 0; scanf("%s",a);scanf("%d",&k);len = strlen(a);l=r=0;while(r<len) {bk[a[r]-'a']++;while(bk[ a[r] - 'a' ] > k) {//注意這是while不是ifbk[ a[l] - 'a']--;l++;} // printf("%lld %d %d \n",ans,l,r);ans+=r-l+1;r++; }printf("%lld\n",ans);} /** //以左端點(diǎn) while(r<len) {if(l == r) {r++;}}//后續(xù)處理 while(l<=r) {} */ return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5056】Boring count (尺取法)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。