博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ——T 2406 Power Strings
阅读量:5238 次
发布时间:2019-06-14

本文共 1561 字,大约阅读时间需要 5 分钟。

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 50627   Accepted: 21118

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

abcdaaaaababab.

Sample Output

143

Hint

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

Source

 
求最短循环节出现次数
1 #include 
2 #include
3 #include
4 5 using namespace std; 6 7 const int N(2333333); 8 int ans,len,p[N]; 9 char s[N];10 11 inline void Get_next()12 {13 for(int i=2,j=0;i<=len;i++)14 {15 for(;s[i]!=s[j+1]&&j>0;) j=p[j];16 if(s[i]==s[j+1]) j++;17 p[i]=j;18 }19 }20 21 int main()22 {23 for(scanf("%s",s+1);s[1]!='.';scanf("%s",s+1))24 {25 memset(p,0,sizeof(p));26 len=strlen(s+1);27 Get_next();28 int tmp=len-p[len];29 if(len%tmp) puts("1");30 else printf("%d\n",len/tmp);31 }32 return 0;33 }

 

转载于:https://www.cnblogs.com/Shy-key/p/7382656.html

你可能感兴趣的文章
nios中定时器的使用
查看>>
java获取weblogic应用运行路径
查看>>
实用SQL语句大全
查看>>
20080421
查看>>
Docker - 常用命令集
查看>>
php 日期
查看>>
POJ 1154 LETTERS
查看>>
算法Sedgewick第四版-第1章基础-001递归
查看>>
1-23 类
查看>>
JSqlParser系列之二代码结构(原)
查看>>
linux-vim/编辑器
查看>>
读think in java有感
查看>>
foxmail地址簿导入thunderbird的乱码问题 (转载)
查看>>
智能自然语言交流系统项目总结
查看>>
生成器,推导式
查看>>
设计模式--通用责任链分配模式
查看>>
Binary Search
查看>>
div的拖拽交换位置
查看>>
PHP常用代码段:
查看>>
[第四章] 测试依赖性和异常
查看>>