POJ Power Strings 2406
来源:互联网 发布:2016新鲜网络赚钱项目 编辑:程序博客网 时间:2024/06/05 02:06
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 44948 Accepted: 18770
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
Waterloo local 2002.07.01
题意:kmp求循环节
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;#define maxx 1123456int next[maxx];char t[maxx];void get_next(char t[]){ int l=strlen(t); int i=0,j=-1; next[0]=-1; while(i<l) { if(j==-1 || t[i]==t[j]) { i++;j++;next[i]=j; } else { j=next[j]; } }}int main(){ int n,m,i,j; while(~scanf("%s",t)) { if(strcmp(t,".")==0) { break; } get_next(t); int l=strlen(t); if(l%(l-next[l])==0) printf("%d\n",l/(l-next[l])); else printf("1\n"); } return 0;}
0 0
- poj 2406 "Power Strings"
- poj 2406 Power Strings
- POJ-2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ:2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 - Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- js函数使用技巧
- 猴子选大王
- java查漏补缺(三)
- SLAM-谷歌Cartographer学习资料
- HDU2085 核反应堆
- POJ Power Strings 2406
- KNN
- 菲波那切数列 php
- 201. Bitwise AND of Numbers Range
- LA 2678 Subsequence .
- html简单标签介绍
- kmp算法与next数组值
- 扩展第三方DropDownMenu
- 快速排序