POJ
来源:互联网 发布:买刷枪软件 编辑:程序博客网 时间:2024/05/14 09:05
KMP进阶
求循环节出现次数(对整串来说) 不存在能覆盖全串的循环节的话 是 1
如果存在的话在超出串的
第一个位置的前匹配点就是上个循环节结束的位置
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 1e7 + 7, maxd = 1e4 + 7, mod = 1e9 + 7;const ll INF = 0x7f7f7f7f;int len, ans;char s[maxn];int f[maxn];void init() { f[0] = f[1] = 0; for(int i = 1; i < len; ++i) { int j = f[i]; while( j && s[i] != s[j]) j = f[j]; f[i+1] = (s[i] == s[j] ? j+1 : 0); }// for(int i = 0; i <= len; ++i)// cout << f[i] << " ";}int main() { while(~scanf("%s", s) && s[0] != '.') { len = strlen(s); init(); if(len % (len-f[len]) == 0) printf("%d\n", len / (len-f[len])); else puts("1"); } return 0;}
阅读全文
1 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- STL模拟实现List+迭代器
- CentOS7使用firewalld打开关闭防火墙与端口
- Hibernate-配置详解(一)
- 【笔记+模板】ST 表
- log4j日志的使用
- POJ
- 会计程序编写.
- ZBrush有多少版本?ZBrush下载集合
- 用Verilog HDL语言实现UART通信
- leetcode题解-8. String to Integer (atoi)
- 复归
- Python 字符串操作方法大全
- 阿里云服务器ces
- Spring Boot 快速上手(六)集成MongoDB