设为首页 加入收藏

TOP

G - Power Strings POJ 2406 (字符串的周期)
2015-11-21 01:00:51 来源: 作者: 【 】 浏览:1
Tags:Power Strings POJ 2406 字符串 周期

G - Power Strings
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice POJ 2406

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.

1.直接暴力枚举

?

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; const int maxn=1000005; typedef long long LL; char s[maxn]; int main(){ int T; //freopen("Text//in.txt","r",stdin); while(~scanf("%s",s)&&s[0]!='.'){ int len=strlen(s); for(int i=1;i<=len;i++)if(len%i==0){ int ok=1; for(int j=i;j
        
         

?

2.kmp算法 i-next[i]:表示已i结尾的前缀的循环节的长度

?

#include
          
           
#include
           
             #include
            
              #include
             
               #include
              
                #include
               
                 using namespace std; const int maxn=1000005; typedef long long LL; char s[maxn]; int next[maxn]; void getnext(char*s){ int len=strlen(s); int i=0,j=-1; next[0]=-1; while(i
                
                 

?

?

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 1166 敌兵布阵(单点更新线段.. 下一篇UVA10048 - Audiophobia(Floyd,最..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: