F - Power Strings

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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

  1. abcd
  2. aaaa
  3. ababab
  4. .

Sample Output

  1. 1
  2. 4
  3. 3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.
 
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<map>
  5. #define maxn 10010000
  6. using namespace std;
  7. char p[maxn];
  8. int next[maxn],len;
  9. int kmp(){
  10. int i=,j=-;
  11. next[]=-;
  12. while(i<len){
  13. if(j==-||p[i]==p[j]) next[++i]=++j;
  14. else j=next[j];
  15. }
  16. }
  17. int main()
  18. {
  19. while(scanf("%s",p)!=EOF&&p[]!='.'){
  20. len=strlen(p);
  21. kmp();
  22. if(len%(len-next[len]))printf("1\n");
  23. else printf("%d\n",len/(len-next[len]));
  24. }
  25. return ;
  26. }

POJ 2406 Power Strings的更多相关文章

  1. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  2. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

  3. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  4. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  5. KMP + 求最小循环节 --- POJ 2406 Power Strings

    Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...

  6. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  7. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

  8. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

  9. poj 2406 Power Strings(KMP变形)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 D ...

随机推荐

  1. (ios7) 解决Ios7中,Navigatebar 显示在主View中,和ios6 不一致问题

    在ios 7 系统中 NavigateBar 显示在主View中 ,Ios6 不在主View中,导致后台代码的方式编写View不一致 解决方法: 在ViewControl的viewDidLoad 方法 ...

  2. SQLServer中登录名的用户名配置

    其实这个问题困扰我很久了. 今夏(13.7)实习的时候第一次接触sqlserver 当时是统一安排,按部就班的做就行. 那时候链接数据库用的id是sa. 后来自己做小程序时候举得不管什么都用sa登录好 ...

  3. CentOS 7 安装Docker

    1.安装前检查: a.内核版本 uname -a b.检查Device Mapper ls -l /sys/class/misc/device-mapper 2.安装Docker: a.更新系统包到最 ...

  4. ubuntu创建、删除文件及文件夹方法

    mkdir 目录名         => 创建一个目录 rmdir 空目录名      => 删除一个空目录 rm 文件名 文件名   => 删除一个文件或多个文件 rm –rf 非 ...

  5. 关于CPU Cache:程序猿需要知道的那些

    天下没有免费的午餐,本文转载于:http://cenalulu.github.io/linux/all-about-cpu-cache/ 先来看一张本文所有概念的一个思维导图: 为什么要有CPU Ca ...

  6. hibernate查询方式

    hibernate查询方式:1.本地SQL查询 2.HQL查询 3.QBC查询 HQL查询:是面向对象的查询语言,是使用最广的一种查询方法 QBC查询:Query by Criteria是一套接口来实 ...

  7. QT的QWebView显示网页不全

    最近使用QWebView控件遇到一个问题,就是无论窗口多大,网页都显示那么大,而且,显示不完全,有滚动条 试过使用showMaximized()方法, 还是一样,网上一直说是布局问题,也没说清楚是虾米 ...

  8. echo

    echo $echo [-e] [内容字符串]显示后面的内容,缺省选项表示将后面的内容原模原样的显示出来,如果后面接的字符串不用"",会默认以空格为分隔符输出多个串 可以配合She ...

  9. Linux系统升级更新openssh 7.3p1

    放在最前面:鉴于网上爬虫猖獗,博客被盗时有发生,这里需要来个链接,大家请认准来自博客园的Scoter:http://www.cnblogs.com/scoter2008,本文将持续更新 最近绿盟给扫描 ...

  10. Reducejoin sample

    示例文件同sample join analysis 之前的示例是使用map端的join.这次使用reduce端的join. 根据源的类别写不同的mapper,处理不同的文件,输出的key都是stude ...