做此题,只要理解好next数组就行.......................

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
char str[411111],tmp[411111];
int next[411111],ans[411111]; void getnext(char *t) {
int i=0,j=-1;
int len = strlen(t);
next[0] = -1;
while(i < len) {
if(t[i] == t[j] || j == -1) {
i ++;
j ++;
next[i] = j;
} else j = next[j];
}
}
/*
int kmp(char *s,char *t) {
int lens = strlen(s);
int lena = strlen(t);
int i=0,j=0;
while(i < lens && j < lena) {
if(s[i] == t[j] || j == -1) {
i++;
j++;
} else j = next[j];
}
if(j < lena) return -1;
return i - lena;
}
*/
int main() {
while(scanf("%s",str) != EOF) {
strcpy(tmp,str);
int len = strlen(str);
int cnt = 0;
getnext(str);
int j = next[len];
ans[cnt++] = j;
while(j > 1) {
ans[cnt++] = next[j];
j = next[j];
}
for(int i=cnt-1; i>=0; i--) {
if(ans[i] != 0)
printf("%d ",ans[i]);
}
printf("%d\n",len);
}
return 0;
}

POJ 2752 Seek the Name, Seek the Fame(next数组的理解)的更多相关文章

  1. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  2. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

  3. Seek the Name, Seek the Fame POJ - 2752

    Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应 ...

  4. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...

  5. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  6. poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Ac ...

  7. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

  8. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

    Seek the Name, Seek the Fame Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 24000 ...

  9. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

随机推荐

  1. phpmyadmin登陆提示#2002 无法登录 MySQL 服务器和设置自增

    看看mysql启动没有,结果是mysql服务没有启动,找了半天,是这个原因,那就右键计算机->管理->服务->启动mysql服务 设置自增:在显示出来的一行字段定义中把浏览器的滚动条 ...

  2. Lesson 7: Responsive Typography In Action

    Lesson 7: Responsive Typography In Action 排版一直都是设计和传达的基础.虽然现在的设计和印刷品设计差别很大,但核心原则还是不变的. Article 1: Bo ...

  3. iOS 网络与多线程--6.下载并保存网络图片

    使用二进制数据对象的,从制定网站获取数据的方法,下载网络图片,并转化为二进制数据,然后将二进制数据保存到磁盘 按照注释需要进行阅读以下代码 // Created by JinXin on 15/12/ ...

  4. CIPAddressCtrl控件

    CIPAddressCtrl m_ipCtrl; 1.获取控件IP值 int GetAddress(byte& byteFirst, byte& byteTwo, byte& ...

  5. crtmpserver的架构简介

    crtmpserver的架构简介 一.层 Layers . 机器层 Machine layer . 操作系统层 Operating System Layer   This layer is compo ...

  6. 流Stream个人学习理解

    1.Stream类 命名空间:System.IO 程序集:mscorlib 流是对字节序列的抽象,提供字节序列的一般视图. 流的操作包括三个方面: 1.读取(Read):将流数据传入到数据结构 2.写 ...

  7. WordPress插件制作笔记(一)---First Plugins Demo

    1->add_action  HOOK简单说明: http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址) //在后台页脚位置加 ...

  8. Mac下安装MySQL-python

    前提系统中已安装python.mysql数据库: 第一步(终端输入): $ export PATH=$PATH:/usr/local/mysql/bin 第二步(终端输入): $ sudo pip i ...

  9. TFT LCD控制显示总结(硬件概念、初始化相关配置)(转)

    源地址:http://nervfzb.blog.163.com/blog/static/314813992011215105432369/ TFT LCD是嵌入式中比较常用的显示器,S3C2440/S ...

  10. C++服务器linux开发环境管理

    在游戏服务器开发中,跨平台不是必须的.线上游戏既有windows下的C++..Net服务器也有linux下的C++.go.erlang服务器.但是无论如何都要保证开发环境和线上运行环境的一致,否则不同 ...