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

不是应该用KMP吗???

Posted by 2730052770 at 2017-07-25 20:45:04 on Problem 2406
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char a[1000005];
int next[1000005];
void getnext()
{
	int len=strlen(a);
	next[0]=0,next[1]=0;
	for(int i=1;i<len;i++){
		int j=next[i];
		while(j&&a[i]!=a[j]) j=next[j];
		next[i+1]=a[i]==a[j]?j+1:0;
	}
	int maxans=len-next[len];
	if((len%maxans)) puts("1");
	else printf("%d\n",len/maxans);
}
int main()
{
	while(scanf("%s",a)) 
		if(a[0]!='.') getnext();
		else 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