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

请教一下,偶的程序哪里写错了,总是TLE

Posted by Maximum at 2006-01-23 01:26:03 on Problem 2752
#include <stdio.h>
#include <string.h>
#include <ctype.h>

char s[400001];
int n;

int next[40001];
int nrec;
int rec[40001];

main() {
	int x; char ch;
	
//	freopen( "e.in", "r", stdin );
//	freopen( "e.out", "w", stdout );
	
	while( (ch = getchar()) != EOF ) {
		if( !islower(ch) ) break;
		n = 0;
		do {
			s[n++] = ch;
			ch = getchar();
		} while( islower(ch) );
		x = 0;
		for( int i = 1; i < n; i++ ) {
			while( x && s[i] != s[x] ) x = next[x];
			if( s[i] == s[x] ) x++;
			next[i] = x;
		}
		nrec = 0;
		for( x = n-1; x >= 0; x = next[x]-1 ) rec[nrec++] = x;
		for( int i = nrec-1; i >= 0; i-- ) printf( "%d ", rec[i]+1 );
		printf( "\n" );
	}
}


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