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

原创算法,141ms

Posted by lyyshp at 2016-03-13 12:02:35 on Problem 3974
#include <stdio.h>
int a[1000001];
char s[1000001] = {0};
int main()
{
	int m, i, c, j, x, t, k = 1;
	while( scanf( "%s", s ) && s[0] != 'E' ){
		if( !s[1] ){
			printf( "Case %d: 1\n", k ++ );
			continue;
		}
		m = 1, c = 1, a[0] = 0;
		if( s[1] == s[0] ) m = 2;
		else a[1] = 1, c = 2;
		for( i = 2; s[i]; i ++ ){
			for( j = 0, t = c - 1, c = 0; j < t; j ++ ){
				if( -- a[j] >= 0 && s[a[j]] == s[i] ){
					a[c ++] = a[j];
					x = i - a[j] + 1;
					if( x > m ) m = x;
				}
			}
			if( s[i] == s[i - 1] ){
				a[c ++] = a[t];
			}
			else{
				if( -- a[t] >= 0 && s[a[t]] == s[i] ){
					a[c ++] = a[t];
					x = i - a[t] + 1;
					if( x > m ) m = x;
				}
				else{
					x = i - a[t] - 1;
					if( x > m ) m = x;
				}
				a[c ++] = i;
			}
		}
		if( s[i - 1] == s[i - 2] ){
			x = i - a[c - 1];
			if( x > m ) m = x;
		}
		printf( "Case %d: %d\n", k ++, m );
	}
	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