首页 > 其他 > 详细

hdu 1358 Period

时间:2015-08-18 19:36:22      阅读:216      评论:0      收藏:0      [点我收藏+]

对next数组还是理解的不够透彻,要死要死要死

#include<iostream>
#define maxn 1001000 
using namespace std;
string str;
int nextt[maxn];
void kmp()
{
	int l=0,k=-1;
	nextt[0]=-1;
	while(l<str.size())
	{
		if(k==-1||str[l]==str[k]) nextt[++l]=++k;
		else k=nextt[k];
	}
}
int main()
{
	int n;
	int casee=1;
	cin.sync_with_stdio(false);
	while(cin>>n&&n)
	{
		cin>>str;
		kmp();
		int ans=0;
		cout<<"Test case #"<<casee++<<endl;
		for(int i=2;i<=n;i++)
		{
			int temp=i-nextt[i];
			if(i%temp==0&&i!=temp)
			{
				ans=i/temp;
				cout<<i<<" "<<ans<<endl;
			}
		}
		cout<<endl;
		
	}
	return 0;
} 


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu 1358 Period

原文:http://blog.csdn.net/zafkiel_nightmare/article/details/47753929

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!