hdu3374 String Problem

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374


题解:循环移位,找字典序最前的和字典序最后的下标标号,然后把次数也输出来。

用最小表示法和最大表示法找到字典序最小和最大的字符串。用kmp计算出现的次数(最小循环周期)。

//http://blog.csdn.net/coraline_m/article/details/9834619


#include 
#include 
#define MAXN 1000002

char str1[MAXN];
int next[MAXN],len;

void getNext()
{
	int i=0,j=-1;
	next[0]=-1;
	while(str1[i]!='\0')
	{
		if(j==-1||str1[i]==str1[j])
		{
			i++;
			j++;
			next[i]=j;
		}
		else
			j=next[j];
	}
}

int getMin()//最小表示法
{
	int i=0,k=0,j=1,t;
	while(i0)
				i+=(k+1);
			else
				j+=(k+1);
			if(i==j)
				j++;
			k=0;
		}
	}
	return i0)
				j+=(k+1);
			else
				i+=(k+1);
			if(i==j)
				j++;
			k=0;
		}
	}
	return i



你可能感兴趣的:(KMP)