HDU 1358 Period

Source: Internet
Author: User

HDU 1358 Period
PeriodTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 3749 Accepted Submission (s): 1841



Problem Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, aggressive), we want to know whether the prefix is a periodic string. that is, for each I (2 <= I <= N) we want to know the largest K> 1 (if there is one) such that the prefix of S with length I can be written as AK, that is A concatenated K times, for some string. of course, we also want to know the period K.

Input The input file consists of several test cases. each test case consists of two lines. the first one contains N (2 <= N <= 1 000 000)-the size of the string S. the second line contains the string S. the input file ends with a line, having the number zero on it.

Output For each test case, output "Test case #" and the consecutive test case number on a single line; then, for each prefix with length I that has a period K> 1, output the prefix size I and the period K separated by a single space; the prefix sizes must be in increasing order. print a blank line after each test case.

Sample Input

3aaa12aabaabaabaab0

Sample Output
Test case #12 23 3Test case #22 26 29 312 4


Uh .. The meaning is that, starting from the second position, if there is the same loop string before, the output position is the following table at this time and the number of loop strings is output. Idea: run a KMP (only the value of the moving distance between a certain position and the current position is the 1/m of the current position, when the value in the next array is not 0, a loop string appears. (I do not know if this is true ).. ..
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       # Include
        
          Using namespace std; # define mod 1000000007 # define inf 0x7f7f7f7fint Next [1000005]; char s [1000005]; // optimistic about the question, the array opens 100 W, I opened 10WRE many times .. Int l; void getNext () {int I, j; I = 0; j =-1; Next [I] = j; while (I
         
           > N, n) {scanf ("% s", s); l = strlen (s); memset (Next, 0, sizeof (Next); getNext (); printf ("Test case # % d \ n", ++ Case); int k; // for (k = 0; k
          
            So, find
          
         
        
      
     
    
   
  
 

Related Article

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.