SDUTOJ 2476Period

#include<iostream>
#include<string.h>
#include<stdio.h>
#define N 1000010
using namespace std;
char s[N];
int next[N];
void getnext(char s[])
{
	int j=-1,i=0,len;
	next[0]=-1;
        len=strlen(s);
	while(i<=len)
	{
		if(j==-1||s[i]==s[j])
		{
			++i;
			++j;
			next[i]=j;
		}
		else
		    j=next[j];
	}
}
int main()
{
	int j=1,i,n;
	while(cin>>n)
	{
		if(n==0)
		{
			break;
		}
		else
		cin>>s;
		getnext(s);
		cout<<"Test case #"<<j<<endl;
		j++;
		for(i=2;i<=n;i++)
		{
			if(i%(i-next[i])==0 && i!=i-next[i])
				cout<<i<<" "<<(i/(i-next[i]))<<endl;
		}
		cout<<"\n";
	}
	return 0;
}

时间: 2024-12-19 04:25:02

SDUTOJ 2476Period的相关文章

sdutoj 2605 A^X mod P

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2605 A^X mod P Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 It's easy for ACMer to calculate A^X mod P. Now given seven integers n, A, K, a, b, m, P, and a function

sdutoj Thrall’s Dream

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2604 Thrall’s Dream Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought

sdutoj Rescue The Princess

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To re

图结构练习——判断给定图是否存在合法拓扑序列(sdutoj)

#include<stdio.h>#include<string.h>int d[15],map[15][15],vis[15];int main(){    int i,j,k,f,n,m,u,v;    while(~scanf("%d%d",&n,&m))    {        memset(d,0,sizeof(d));        memset(map,0,sizeof(map));        memset(vis,0,size

sdutoj Mountain Subsequences

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607 Mountain Subsequences Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and

KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&amp;problemid=2772)

#include <stdio.h>#include <string.h>#include <stdlib.h>char a[1000001],b[1000001];int next[1000001];int l,l2;void Getnext(){ int i=0; int j=-1; next[0]=-1; while(i<l2) { if(-1==j||b[i]==b[j]) { i++; j++; next[i]=j; } else j=next[j];

sdutoj 2606 Rubik’s cube

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Flabby is addicted to Rubik’s cube. He has many kinds of Rubik’s cube and plays them well. He can reor

关键路径 SDUTOJ 2498

SDUTOJ 2498 AOE网上的关键路径 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 一个无环的有向图称为无环图(Directed Acyclic Graph),简称DAG图.     AOE(Activity On Edge)网:顾名思义,用边表示活动的网,当然它也是DAG.与AOV不同,活动都表示在了边上,如下图所示:                                         如上所示,共有1

SDUTOJ 2772 KMP简单应用

#include<iostream> #include<string.h> #include<stdio.h> #define N 10000001 using namespace std; char s[N],s1[N]; int next[N]; void getnext(char s1[]) { int j=-1,i=0,len; next[0]=-1; len=strlen(s1); while(i<len) { if(j==-1||s1[i]==s1[j