Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

ExKmp不行么?

Posted by DMKaplony at 2010-03-29 19:39:39 on Problem 2752
WA了。。
#include <iostream>

#define MAXL 500000

using namespace std;

char s[MAXL];
int next[MAXL];
int k;
int far;

int main(){
    int i;
    while (scanf(" %s", s) != EOF){
        k = 0;
        for (i=1; s[i]!='\0'; i++){
            if (k <= 0 || (far = k + next[k] - 1) < i){
                next[i] = 0;
                while (s[i + next[i]] == s[next[i]])
                    next[i]++;
                }
            else{
                if (next[i - k] > far - i + 1){
                    next[i] = far - i + 1;
                    while (s[i + next[i]] == s[next[i]])
                        next[i]++;
                    }
                else
                    next[i] = next[i - k];
                }
            if (k <= 0 || far < i + next[i] - 1)
                k = i;
            }
        next[0] = i;
        for (i=0; i<next[0]-1; i++){
            if (next[next[0] - i - 1] == i + 1)
                printf("%d ", i + 1);
            }
        printf("%d\n", next[0]);
        }
    return 0;
    }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator