Power Strings(求循环节)
来源:互联网 发布:笑话软件 编辑:程序博客网 时间:2024/05/17 20:31
题目描述
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).
输入
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.
输出
For each s you should print the largest n such that s = a^n for some string a.
示例输入
abcdaaaaababab.
示例输出
143
提示
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
#include<stdio.h>#include<string.h>char s[2000000];int next[2000000];int getnext(char st[],int next[]){ int i=0,j=-1; next[0]=-1; while(st[i]!='\0') if(j==-1||st[i]==st[j]) { i++; j++; next[i]=j; }else j=next[j]; if(j==0) return -1; else return i-j;}int main(){ int len; while(scanf("%s",s),strcmp(s,".")) { len=strlen(s); int l=getnext(s,next); if(l==-1||len%l) printf("1\n"); else printf("%d\n",len/l); } return 0;}
0 0
- Power Strings(求循环节)
- 【poj2406】 Power Strings (KMP求循环节)
- poj2406--Power Strings(KMP求最小循环节)
- POJ 2406 Power Strings(KMP求最小循环节)
- [poj2406]Power Strings(kmp求最小循环节)
- 【POJ 2406】 Power Strings(KMP求循环节)
- poj2406(KMP 求循环节的个数)Power Strings --
- (POJ2406)Power Strings <KMP算法求最小循环节>
- poj2406 Power Strings(kmp求最小循环节)
- Power Strings(kmp next求循环节)
- poj2406 Power Strings(kmp求循环节)
- POJ 2406 Power Strings KMP 求最小循环节
- UVA - 10298 Power Strings (KMP求字符串循环节)
- POJ 2406Power Strings kmp算法求循环节
- POJ 2406 Power Strings (kmp求循环节)
- KMP + 求最小循环节 --- POJ 2406 Power Strings
- 【KMP求最小循环节】POJ2406 Power Strings
- 【poj 2406】 Power Strings 【KMP 求最小循环节】
- linux中的一些基本操作
- 华为机试:大数相减
- cocos2d-x实现3D模型的换装系统的研究
- 计算机网络常见笔试题
- ARM处理器中的“8位位图”
- Power Strings(求循环节)
- 数组(一维数组和二维数组)的用法
- Eclipse常用快捷键
- 我之见--java多线程阻塞与非阻塞
- 阿里云服务器
- Android 自定义View,自定义属性--自定义圆形进度条(整理)
- 用Gradle 构建你的android程序
- day26,page50,total150
- N-Queens