POJ 2406 Power Strings (KMP NXT Array for Minimum loop section)

Source: Internet
Author: User

Title Link: Poj 2406 Power Strings

Test instructions

Give you a string that lets you find out the maximum number of loops for this string, and the minimum loop.

Exercises

Using KMP's NXT array, l=j-nxt[j], is the smallest follow-up link to the prefix J.

1#include <cstdio>2#include <algorithm>3#include <cstring>4 #defineF (I,A,B) for (int i= (a); i<= (b); ++i)5 using namespacestd;6 7 voidKmp_pre (Char*x,intMint*NXT) {8     inti,j;9j=nxt[0]=-1, i=0;Ten      while(i<m) { One          while(-1!=J&AMP;&AMP;X[I]!=X[J]) j=Nxt[j]; Anxt[++i]=++J; -     } - } the  - Const intn=1e6+7; - CharS[n]; - intNxt[n],n; +  - intMain () { +      while(~SCANF ("%s", s)) A     { at         if(*s=='.') Break; -n=strlen (s); - Kmp_pre (S,N,NXT); -         intans=1; -         if(n% (n-nxt[n]) = =0) ans=n/(nnxt[n]); -printf"%d\n", ans); in     } -     return 0; to}
View Code

POJ 2406 Power Strings (KMP NXT Array for Minimum loop section)

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.