POJ 2406 Power Strings KMP 求最小循环节
来源:互联网 发布:dbc数据库详解 编辑:程序博客网 时间:2024/05/17 03:28
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 29027 Accepted: 12124
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
给定一个字符串m,求一个最短的子串n,m是n重复多次组成的(求m的最小循环节)。
利用kmp中next(我的数组名是p)数组的性质。
表达能力拙计。。。分析样例的next数组找数学规律吧。
还有,用cin是可以AC的。
#include <iostream>using namespace std;string s;int l,i,j,p[1000010];int main(){ios::sync_with_stdio(false);while (cin>>s && s!="."){l=s.size();j=-1; p[0]=-1;for (i=1;i<l;++i){while (j>-1 && s[i]!=s[j+1]) j=p[j];if (s[i]==s[j+1]) ++j;p[i]=j;}i=l-p[l-1]-1;if (l%i==0) cout<<l/i<<endl; else cout<<"1\n";}return 0;}
kdwycz的网站: http://kdwycz.com/
kdwyz的刷题空间:http://blog.csdn.net/kdwycz
0 0
- POJ 2406 Power Strings KMP 求最小循环节
- POJ 2406 Power Strings(KMP求最小循环节)
- KMP + 求最小循环节 --- POJ 2406 Power Strings
- 【poj 2406】 Power Strings 【KMP 求最小循环节】
- poj 2406 Power Strings 【KMP求最小循环节】【后缀数组求连续重复子串】
- POJ 2406 Power Strings【KMP求最小循环节/后缀数组】
- POJ 2406 Power Strings 求最小循环节数(KMP)
- poj 2406 Power Strings (KMP+最小循环节)
- POJ 2406 Power Strings(KMP+最小循环节)
- 【POJ 2406】 Power Strings(KMP求循环节)
- POJ 2406Power Strings kmp算法求循环节
- POJ 2406 Power Strings (kmp求循环节)
- POJ - 2406 Power Strings (KMP循环节)
- POJ - 2406 Power Strings(KMP 循环节)
- POJ 2406 Power Strings [KMP+循环节]
- POJ 2406 Power Strings(KMP循环节)
- poj 2406 Power Strings【kmp循环节】
- poj2406--Power Strings(KMP求最小循环节)
- UVA 12538 可持久化treap入门
- EBS Form开发利用QUERY_FIND来实现最简单的查询功能(2)
- Jos-lab3 (Exercise 1 & 2)
- Tcp/ip moniter
- 英雄会(csdn pongo)题解之平衡二叉树——C++源代码
- POJ 2406 Power Strings KMP 求最小循环节
- Length of Last Word 最后一个单词的长度
- Android开发--内容提供者(Content provider)
- LeetCode OJ:Linked List Cycle
- ACM HDOJ 1251 (统计难题 )
- 【每天一个Linux命令】1. ln -s 软链接
- 4.在二元树中找出和为某一值的所有路径(树)
- poj2823
- # winform listView鼠标拖拽到pictureBox问题的解决办法,鼠标拖动