//应该判断是否是循环节就是求的next数组
//5032K 172MS
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAX_N 1000007
static char mol[MAX_N];//模式串
static void initNext(int*NEXT)
{
int p=0,q= -1;
NEXT[0] = -1;
int n = strlen(mol);
while(p<n)
{
if (q==-1||mol[p]==mol[q])
{
NEXT[++p] = ++q;
}
else
q = NEXT[q];
}
}
int POJ1961()
{
int n;
int NEXT[MAX_N] = {};
int ncase = 1;
while(scanf("%d",&n))
{
if (n==0)
break;
scanf("%s",mol);
int ret = 0;
printf("Test case #%d\n",ncase);
initNext(NEXT);
for (int i=1;i<=n;++i)
{
int length = i - NEXT[i];
if (i!=length&&i%length==0)
{
printf("%d %d\n",i,i/length);
}
}
printf("\n");
ncase++;
}
return 0;
}
poj1961与poj2406同都是寻找循环节
最新推荐文章于 2017-08-01 16:15:56 发布