Power Strings (kmp中next数组的运用)
来源:互联网 发布:足球怎么过人知乎 编辑:程序博客网 时间:2024/06/05 21:51
【题目来源】:https://vjudge.net/problem/POJ-2406
【题意】
给出一个字符串,问其最小循环周期是多少。
【思路】
利用kmp中next数组的特殊性,也就是若字符串长度为len,则在1~len里,假设i在1~n,那么假设长度为i,那么其的最小循环周期是i-next[i]。
可以自行证明。
【代码】
#include<set>#include<map>#include<stack>#include<cmath>#include<queue>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<limits.h>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;const int mod=1e9+7;const double esp=1e-5;typedef unsigned long long ll;typedef long long LL;char s[1000000+10];int nexts[1000000+10];int len;void get_next(){ int i,j; j=nexts[0]=-1; i=0; while(i<len) { while(-1!=j&&s[i]!=s[j]) j=nexts[j]; nexts[++i]=++j; }}int main(){ while(~scanf("%s",s)&&s[0]!='.') { len=strlen(s); get_next(); int ans=1; if(len%(len-nexts[len])==0) ans=len/(len-nexts[len]); printf("%d\n",ans); }}
阅读全文
0 0
- Power Strings (kmp中next数组的运用)
- POJ 2406 Power Strings KMP中next数组简单运用
- POJ2406 Power Strings(KMP next数组的运用)
- 【POJ2406】Power Strings-KMP中next数组的应用
- poj 2406 Power Strings(kmp next数组的应用)
- poj 2406 Power Strings KMP的next数组的应用
- POJ2406 Power Strings KMP-next数组的循环节
- POJ 2406 Power Strings (KMP next数组应用)
- poj 2406 Power Strings kmp next数组
- POJ 2406 Power Strings (kmp next数组)
- kmp中next数组的运用
- Cyclic Nacklace (kmp中next数组的运用)
- Period(kmp中next数组的运用)
- The Minimum Length (kmp中next数组的运用)
- Power Strings poj 2406 kmp的运用
- POJ 2046 Power Strings KMP(next数组应用)
- POJ-Power Strings(next数组应用)
- POJ 2406-Power Strings(重复子串-KMP中的next数组)
- 矢量资源工具Vector Asset Studio
- yocto
- Java时延
- Webpack按需打包Lodash的几种方式
- Linux 下多线程的消费者-生产者模型
- Power Strings (kmp中next数组的运用)
- C语言指针的形象理解-----/*自己编写*/
- 记一次MySQL使用外网IP连接超时
- 经典JUnit测试
- [YTU]_2354 (实现复数类中的加运算符重载【C++运算符重载】)
- 文件本身操作NSManager
- Android_UI:Activity
- vue--computed
- 选择排序