zoukankan      html  css  js  c++  java
  • HDU 1358 Period

    题意:求该字符串(前面一部分)存在循环的最小循环节是多少,输出所有满足该条件的  前缀长度和最小循环节长度

    #include <stdio.h>
    char P[1000010];//从0开始存
    int f[1000010];//记录P的自我匹配
    int Len;
    void getFail(){
    	int m=Len;
    	f[0]=f[1]=0;
    	for(int i=1;i<m;i++){
    		int j=f[i];
    		while(j&&P[i]!=P[j])j=f[j];
    		f[i+1]= P[i]==P[j] ? j+1 : 0;
    	}
    }
    
    int main(){
    	int Case=1;
    	while(scanf("%d",&Len),Len){
    		scanf("%s",P);
    		getFail();
    		printf("Test case #%d
    ",Case++);
    		for(int i=2;i<=Len;i++)
    			if(f[i]>0 && i% (i-f[i])==0)
    				printf("%d %d
    ",i,i/(i-f[i]));
    		printf("
    ");
    	}
    	return 0;
    }


  • 相关阅读:
    8.26 树状数组
    8.27 神异之旅
    8.26 雇佣
    8.28 Jack与Rose
    8.28 ISN
    保存和加载网络
    快速搭建网络
    分类网络
    torch中的回归
    pytorch中的Variable
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3249245.html
Copyright © 2011-2022 走看看