• 【POJ 2406 Power Strings】


    Time Limit: 3000MS
    Memory Limit: 65536K

    Description

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

    Input

    Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

    Output

    For each s you should print the largest n such that s = a^n for some string a.

    Sample Input

    abcd
    aaaa
    ababab
    .
    

    Sample Output

    1
    4
    3
    

    Hint

    This problem has huge input, use scanf instead of cin to avoid time limit exceed.

    Source

    Waterloo local 2002.07.01

    题解:
          ①找出最小循环节————KMP

    #include<stdio.h>
    #include<cstring>
    #define go(i,a,b) for(int i=a;i<=b;i++)
    const int N=4000003;int m,f[N],j;char P[N]; 
    int main()
    {
    	f[0]=f[1]=0;
    	while(scanf("%s",P),m=strlen(P),P[0]!='.')
    	{
    		go(i,1,m-1){j=f[i];while(j&&P[i]!=P[j])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}
    		printf("%d
    ",m%(m-f[m])?1:m/(m-f[m]));
    	}
    	return 0;
    }//Paul_Guderian
    

    镜子里面,像看到人生终点,或许再过上几年

    你也有张虚伪的脸,难道我们,是为了这样,才来到这世上……—————《你曾是少年》

  • 相关阅读:
    [数据结构]直接插入排序
    隐藏小程序scroll-view组件的滚动条
    当 uni-app 遇见 vscode
    npm(你怕吗) 全局安装与本地安装、开发依赖和生产依赖
    Vue-resource的使用
    spy-debugger调试、抓包工具
    一个小时学会Git
    flex布局踩过的坑
    Html5移动端布局及(rem布局)页面自适应布局详解
    使用vscode自动编译less
  • 原文地址:https://www.cnblogs.com/Damitu/p/7655985.html
Copyright © 2020-2023  润新知