POJ2752 Seek the Name, Seek the Fame(kmp)
来源:互联网 发布:无缝贴图软件 编辑:程序博客网 时间:2024/05/16 16:59
题目链接:点击打开链接
给你一个字符串,要你从小到大输出重复子串的长度。
利用nxt数组性质,将长度从大到小保存到ans数组中,最后逆序输出答案。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 4e5 + 5;char s[MAXN];int nxt[MAXN], ans[MAXN], len;void get_nxt(){nxt[1] = 0;int j = 0;for(int i = 2; i <= len; ++i) {while(j > 0 && s[j + 1] != s[i])j = nxt[j];if(s[j + 1] == s[i]) j++;nxt[i] = j;}}int main(int argc, char const *argv[]){while(scanf("%s", s + 1) != EOF) {memset(nxt, 0, sizeof(nxt));memset(ans, 0, sizeof(ans));len = strlen(s + 1);get_nxt();int x = nxt[len], num = 0;if(x) ans[num++] = x;while(nxt[x] > 0) {x = nxt[x];ans[num++] = x;}for(int i = num - 1; i >= 0; --i)printf("%d ", ans[i]);printf("%d\n", len);}return 0;}
1 0
- 【KMP】 poj2752 Seek the Name, Seek the Fame
- poj2752 Seek the Name, Seek the Fame--------KMP
- poj2752 Seek the Name, Seek the Fame KMP
- POJ2752 Seek the Name, Seek the Fame 【KMP】
- POJ2752 Seek the Name, Seek the Fame KMP算法
- POJ2752 Seek the Name, Seek the Fame【KMP】
- POJ2752 Seek the Name, Seek the Fame(KMP)
- POJ2752 Seek the Name, Seek the Fame(kmp)
- 【poj2752】Seek the Name, Seek the Fame(KMP)
- 【poj2752】Seek the Name, Seek the Fame KMP
- POJ2752 Seek the Name, Seek the Fame KMP
- poj2752 Seek the Name, Seek the Fame (kmp)
- POJ2752 Seek the Name, Seek the Fame KMP应用
- kmp算法 poj2752 Seek the Name, Seek the Fame
- 【POJ2752】Seek the Name, Seek the Fame-KMP思想
- kmp杂题3 poj2752 Seek the Name, Seek the Fame
- 【POJ2752】Seek the Name, Seek the Fame(KMP)
- poj2752 Seek the Name, Seek the Fame(KMP)
- NY58 最少步数
- POJ2406 Power Strings(kmp)
- 记2015年的国庆节--给自己
- 自动布局Autoresizing autolayout VFL
- POJ - 2785 4 Values whose Sum is 0(二分搜索)
- POJ2752 Seek the Name, Seek the Fame(kmp)
- JS点名神器
- php获取内容中的所有图片
- POJ3461 Oulipo(kmp)
- Java 基本类型 long 的一些使用陷阱
- IOS HTTP GET POST学习笔记
- 迅雷 API 接口说明文档 -调用迅雷自动下载
- HTTP协议规定的 - URL中的保留字符
- 手势识别器