程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 3693 Maximum repetition substring

POJ 3693 Maximum repetition substring

編輯:C++入門知識

 

 

 

Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

[Submit] [Go Back] [Status]

Description

The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings. For example, the repetition number of ababab is 3 and ababa is 1.

Given a string containing lowercase letters, you are to find a substring of it with maximum repetition number.

Input

The input consists of multiple test cases. Each test case contains exactly one line, which
gives a non-empty string consisting of lowercase letters. The length of the string will not be greater than 100,000.

The last test case is followed by a line containing a '#'.

Output

For each test case, print a line containing the test case number( beginning with 1) followed by the substring of maximum repetition number. If there are multiple substrings of maximum repetition number, print the lexicographically smallest one.

Sample Input

ccabababc
daabbccaa
#

Sample Output

Case 1: ababab
Case 2: aa

Source

2008 Asia Hefei Regional Contest Online by USTC

[Submit] [Go Back] [Status]

\

 

#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

const int maxn=1000012;

int sa[maxn],rank[maxn],rank2[maxn],h[maxn],c[maxn],*x,*y,ans[maxn];
char str[maxn];

bool cmp(int* r,int a,int b,int l,int n)
{
    if(r[a]==r[b]&&a+l=0;i--) sa[--c[x[y[i]]]]=y[i];
}

void get_sa(char c[],int n,int sz=128)
{
    x=rank,y=rank2;
    for(int i=0;i=len) y[yid++]=sa[i]-len;

        radix_sort(n,sz);

        swap(x,y);
        x[sa[0]]=yid=0;

        for(int i=1;i=n) break;
    }
    for(int i=0;ir) swap(l,r);
    int a=l+1,b=r;
    int k=Log[b-a+1];
    return min(dp[a][k],dp[b-(1<=0&&k%l!=0)
                {
                    if(lcp(t,t+l)>=k) r++;
                }
                if(r>maxx)
                {
                    a=0;
                    maxx=r;
                    ans[a++]=l;
                }
                else if(r==maxx)
                {
                    ans[a++]=l;
                }
            }
        }
        int pos;
        int st,b=0,c;
        for(int i=0;i=(maxx-1)*tl)
                {
                    st=sa[i];
                    pos=i;
                    l=tl*maxx;
                    b=1;
                    break;
                }
            }
        }
        printf(Case %d: ,cas++);
        for (int i=0;i

 

 

 

 

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved