这题数据水的一B。直接暴力都能够过。

比赛的时候暴力过的。回头依照正法做了一发。

匹配的时候 失配函数 事实上就是前缀 后缀的匹配长度,之后就是乱搞了。

KMP的题可能不会非常直接的出,可是KMP的思想常常渗透在非常多题目里面,近期须要多练习一下。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1000005;
int _next[maxn],L;
char s[maxn];
void kmp_init(){
int i,j;
int m = strlen(s);
j = _next[0] = -1;
i = 0;
while(i < m){
while(j != -1 && s[i] != s[j]) j = _next[j];
_next[++i] = ++j;
}
}
bool kmp_solve(int len){
int i,j,m = L - len;
i = len;
j = 0;
while(i < m){
while(j != -1 && s[j] != s[i]) j = _next[j];
i++; j++;
if(j >= len){
return true;
}
}
return false;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",s);
L = strlen(s);
kmp_init();
int i = L - 1;
int ans = 0;
while(_next[i] >= 0){
if(kmp_solve(_next[i] + 1)){
ans = _next[i] + 1;
break;
}
i = _next[i];
}
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. 【翻译】MongoDB指南/引言
  2. vscode过滤pyc文件
  3. 转载-V.I.Arnold, beyond a mathematician
  4. SQLServer中的事务与锁
  5. System.BadImageFormatException : 未能加载文件或程序集“Medici.PaymentRecover, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。
  6. OPENGL学习之路(0)--安装
  7. 在php中写接口时 对json格式的转换 简单的方法
  8. python_GUI
  9. CUBRID学习笔记 8 复制数据库
  10. Peer Code Reviews Made Easy with Eclipse Plug-In
  11. 关于对javascript 提升概念 的总结与思考。
  12. 初识Vim
  13. 在Eclipse中编译maven项目出的问题
  14. MySql 使用规范推荐
  15. JavaScript 对象分类
  16. C++面试笔记(2)
  17. WebStorm连接Github教程
  18. RocketMQ的使用
  19. 1、从C语言到C++
  20. Key Vertex (hdu 3313 SPFA+DFS 求起点到终点路径上的割点)

热门文章

  1. grpc编译错误解决
  2. Struts2国际化-getText()方法
  3. POJ 1631 nlogn求LIS
  4. 如何知道 CPU 是否支持虚拟化技术(VT)
  5. JDOJ 2939: Suffix Automaton 广义后缀自动机_统计子串
  6. div的padding和margin
  7. centos通过yum安装jdk
  8. [TJOI2017]城市(树的直径)
  9. 再谈CLR查找和加载程序集的方式
  10. Unity C# 设计模式(五)建造者模式