POJ-2406-kmp求最小循环节
来源:互联网 发布:单片机如何控制电机 编辑:程序博客网 时间:2024/05/21 08:47
http://poj.org/problem?id=2406
求一个字符串最多由多少个子串重复得到,用kmp里求next数组的方法求得最后一个字母的next【】
如果 next[n]指向的位置的字符与自身相等,且 len%(n-next[n])==0 ,则可证明 字符串存在 len/(n-next[n])个循环节,不满足任一条件,循环节长度只能为1
证明见 :http://blog.csdn.net/viphong/article/details/48498595
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#include <set>#include <vector>#define inf 0x7fffffff#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1const int maxn = 1000005;using namespace std;int nextval[maxn];void get_next(char *t,int len)//失配函数{int i,j;i=1; nextval[1]=0;j=0;while(i<len){if (j==0||t[i]==t[j]){ j++;i++; //if (t[i]!=t[j])nextval[i]=j;//else//nextval[i]=nextval[j];}elsej=nextval[j];}} char tm[maxn]; //主串char nm[maxn];int judge(int x){return 0;}int main( ){ while(scanf("%s",tm+1)!=EOF){if (strcmp(tm+1,".")==0) break;int len=strlen(tm+1);get_next(tm,len);int maxx=nextval[len];int ans;if (len%(len-maxx)==0&& tm[len]==tm[nextval[len]]) ans=len/(len-maxx);elseans=1; printf("%d\n",ans);}return 0;}
0 0
- POJ-2406-kmp求最小循环节
- KMP 求最小循环节 POJ
- 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 1961 Period——kmp求最小循环节
- kmp求最小循环节
- POJ 2406 最小循环节 KMP裸题
- poj 2406 最小循环节kmp
- POJ 2406 KMP求字符串循环节
- POJ 2406 kmp求循环节个数
- poj 2406 KMP求循环节
- POJ 2406 Power Strings【KMP求最小循环节/后缀数组】
- POJ 2406 Power Strings 求最小循环节数(KMP)
- [KMP求最小循环节][HDU1358][Period]
- KMP next数组求最小循环节
- PopupWindow + RecyclerView的使用
- GNU make 101
- marionette中的View的el id className tagName 属性
- 南大软院大神养成计划——第三天
- CountDownTimer的使用以及解决Cancel无效的问题
- POJ-2406-kmp求最小循环节
- 三种同步FIFO的实现方法(verilog实现)
- 真机调试 与 响应者链
- LightOJ 1011 - Marriage Ceremonies(状压DP)
- 欢迎使用CSDN-markdown编辑器
- CentOS 6.5下利用Rsyslog+LogAnalyzer+MySQL部署日志服务器
- 移植libusb到mips-linux上(基于jz4780)
- 学习笔记(一)
- Service后记与拓展