LA-3026 Period(kmp应用)
来源:互联网 发布:iphone7和mac照片同步 编辑:程序博客网 时间:2024/05/20 08:23
题意:给定一个长度为n的字符串s,求它的每个前缀的最短循环节。即对于每个i(i>1),求一个最大的整数k>1,使得S的前i个字符组成的前缀是某个字符串重复K次得到。输出所
有存在K的i和对应的K。
分析:根据KMP中next数组的定义,当(i+1)%(i-next[i]) == 0时,其最短循环节即为(i-next[i]).
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int n,num,Next[1001001];string s;int main(){cin.sync_with_stdio(false);while(cin>>n && n){cout<<"Test case #"<<++num<<endl; cin>>s;int m = s.length();memset(Next,0,sizeof(Next));int now = Next[0] = -1;for(int i = 1;i < m;i++){while(now >= 0 && s[now+1] != s[i]) now = Next[now];if(s[now+1] == s[i]) now++;Next[i] = now;if(now >= 0 && (i + 1)%(i - now) == 0) cout<<i+1<<" "<<(i + 1)/(i - now)<<endl;}cout<<endl;}}
0 0
- LA-3026 Period(kmp应用)
- LA 3026 - Period KMP
- LA - 3026 - Period(KMP)
- LA 3026 - Period KMP失配函数的应用
- LA 3026(Period-MP算法)[Template:KMP]
- LA 3026 Period (KMP失配函数)
- UVALive 3026 (LA 3026) Period KMP求字符串周期
- LA 3026 - Period
- LA 3026 Period
- LA 3026 Period
- UVa LA 3026 Period
- 【43.49】【LA 3026】Period
- LA 3026 Period (strings)
- LA-3026 - Period-MP算法-失配函数-寻找循环节 (kmp)
- LA 3026 && POJ 1961 Period (利用kmp中的next数组找最小的循环节 )
- LA 3026 Period——kmp求n次最小循环节
- UVAlive 3026 Period [KMP]
- UVALIVE 3026 Period(kmp)
- poj3660 Cow Contest
- 如何用IDE调试MR任务(一)(2016-01)
- c语言:求两个数中的最大值(双分支结构)
- java38.Socket通信------使用ServerSocket建立聊天服务器---2
- 解决vs2010中写vb代码时按'''不自动加入函数注释的问题
- LA-3026 Period(kmp应用)
- Android中EditText的字数统计
- Android调用微信登陆、分享、支付
- Android系统之G-sersor调试
- [读书笔记]JVM的垃圾收集算法
- android framework初步理解
- tomcat端口被占用问题解决
- 如何用IDE调试MR任务(二)(2016-01)
- HTML中DIV与SPAN的区别