poj 2752_Seek the Name, Seek the Fame_KMP
来源:互联网 发布:网络推广微信营销方案 编辑:程序博客网 时间:2024/06/05 10:14
题目大意
找出一个字符串中既是前缀也是后缀的字串的长度
思路
利用KMP中next数组的种种玄学性质然后递归输出即可
#include <stdio.h>#include <string>#include <iostream>using namespace std;char a[500000];int p[500000];int print(int x){ if (p[x] > -1) { print(p[x]); printf("%d ", p[x]+1); } return 0;}int main(){ while (gets(a) != NULL) { int n = strlen(a); int j = -1; p[0] = -1; for (int i = 1; i < n; i++) { while (a[j + 1] != a[i] && j != -1) j = p[j]; if (a[j + 1] == a[i]) j++; p[i] = j; } print(n - 1); printf("%d ", n); } return 0;}
阅读全文
1 1
- poj 2752_Seek the Name, Seek the Fame_KMP
- POJ-2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752--Seek the Name, Seek the Fame (next)
- POJ:2752Seek the Name, Seek the Fame
- POJ 2752 - Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ-2752-Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 2752 Seek the Name, Seek the Fame---kmp
- POJ 2752 Seek the Name, Seek the Fame KMP
- poj 2752 Seek the Name, Seek the Fame
- POJ 2752 Seek the Name, Seek the Fame
- poj 字符串相关的水题
- Linux移动物体监控程序Motion的移植
- Android应用的多语言切换
- [python网站开发] 一.Django入门知识及创建第一个网站
- 【算法期末作业】8.3 证明STINGY SAT是NP-完全问题
- poj 2752_Seek the Name, Seek the Fame_KMP
- Android Studio类中实现Serializable自动生成serialVersionUID
- Android-N app seinfo设置流程
- 表驱动初步接触之Map代替if/switch
- 比特币交易(Transaction)的输入与输出
- 面试题10—二进制中1的个数
- js Cannot set property 'color' of undefined
- Websphere安装、企业部署应用举例
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes