hdu-5672 String (ruler)

Source: Internet
Author: User

Topic Links: StringTime limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem Description
Have a10\leq10≤ length\leq 1,000,000 ≤1< Span class= "mpunct" >,000,000 strings, consisting only of lowercase letters. Ask how many substrings, including at least k (1 \leq k \leq) k (1≤k≤ 26) a different letter?  
Enter a description
The input contains multiple sets of data. The first line has an integert (1\leq t\leq) < Span class= "Strut bottom" >t (1≤t≤1< Span class= "Mord" >0s< Span class= "Strut bottom" >s. The second line enters an integer kk.  
Output Description
For each set of data, the output meets the required number of substrings.
Input sample
2abcabcabca4abcabcabcabc3
Output sample
15T

Ideas:

The ruler to find the left border; the final mle of the game, the first is directly put down the status of each position, or while updating the boundary side update the number of letters better;

AC Code:

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<map>using namespaceStd;typedefLong Longll;Constll mod=1e9+7;Const intn=1e6+6;CharS[n];intnum1[ -],num2[ -];intK;intCheck () {intans=0;  for(intI=0;i< -; i++)    {        if(num1[i]-num2[i]>0) {ans++; }    }    if(ans>=k)return 1; return 0;}intMain () {intT; scanf ("%d",&t);  while(t--) {scanf ("%s", s); scanf ("%d",&k); intlen=strlen (s); memset (NUM1,0,sizeof(NUM1)); memset (num2,0,sizeof(num2)); intL=1, r=len+1; num1[s[0]-'a']++; ll ans=0;  for(intI=1; i<=len;i++)        {             while(l<=len&&!Check ()) {L++; if(L<=len) num1[s[l-1]-'a']++; } num2[s[i-1]-'a']++; Ans+ = (ll) (R-l); } printf ("%i64d\n", ans); }    return 0;}

hdu-5672 String (ruler)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.