POJ 2752 Seek the Name, Seek the Fame(kmp)
来源:互联网 发布:淘宝账户永久无法注销 编辑:程序博客网 时间:2024/06/05 11:58
题意:
给你一个串,如果这个串存在一个长度为n的前缀串,和长度为n的后缀串,并且这两个串相等,则输出他们的长度n。求出所有的长度n。
解析:
此题考察kmp next[]数组的应用,不难。
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <cstdlib>using namespace std;typedef long long ll;const int N = 400005;char str[N];int jump[N];vector<int> ans;void getNext() { int j = 0, k = -1; int len = strlen(str); jump[0] = -1; while(j < len) { if(k == -1 || str[j] == str[k]) jump[++j] = ++k; else k = jump[k]; }}int main() { while(scanf("%s", str) != EOF) { ans.clear(); getNext(); int cur = strlen(str); while(cur > 0) { ans.push_back(cur); cur = jump[cur]; } sort(ans.begin(), ans.end()); printf("%d", ans[0]); for(int i = 1; i < ans.size(); i++) { printf(" %d", ans[i]); }puts(""); } return 0;}
0 0
- 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(KMP)
- 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 (KMP)
- 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 (kmp)
- 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(KMP)
- POJ-2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752 Seek the Name, Seek the Fame (KMP)
- poj 2752Seek the Name,Seek the Fame(KMP)
- 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(KMP)
- 三种连接方式的特点
- HTTP状态码404代码500代码等解释
- 新闻发布系统,我学会了什么?
- 【ThinkingInJava】44、数据生成器
- eclipse+webservice开发实例【开发环境jdk1.7.0_67+eclipse-jee-luna+tomcat6.0.30+axis2-1.6.1(此为webservice的jar包)】
- POJ 2752 Seek the Name, Seek the Fame(kmp)
- 安装R package的2种方法
- 14 个 Linux grep 命令的例子
- 贝塞尔曲线
- Number of 1 Bits
- 黑马程序员-----------ios培训 oc内存管理(一)
- OC 使用 “消息结构”
- 【ThinkingInJava】45、用java标准库里面的静态函数调用,复制数组
- 破解TexturePacker加密资源 —— 使用IDA