题目传送门

 /*
题意:求出一个串的前缀与后缀相同的字串的长度
KMP:nex[]就有这样的性质,倒过来输出就行了
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-10 11:29:25
* File Name :POJ_2752.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 4e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int nex[MAXN];
char str[MAXN]; void get_nex(void) {
int len = strlen (str);
int i = , j = -; nex[] = -;
while (i < len) {
if (j == - || str[j] == str[i]) {
j++; i++; nex[i] = j;
}
else j = nex[j];
}
vector<int> ans;
while (i != -) {
ans.push_back (i); i = nex[i];
}
for (int i=ans.size ()-; i>=; --i) {
printf ("%d ", ans[i]);
}
puts ("");
} int main(void) { //POJ 2752 Seek the Name, Seek the Fame
while (scanf ("%s", str) == ) {
get_nex ();
} return ;
}

KMP POJ 2752 Seek the Name, Seek the Fame的更多相关文章

  1. (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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

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

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

  6. poj 2752 Seek the Name, Seek the Fame (KMP纯模版)

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

  7. KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame

    Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...

  8. 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的简单应 ...

  9. POJ 2752:Seek the Name, Seek the Fame

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

随机推荐

  1. 2018/2/17 SpringCloud的一个简单小介绍

    在学习SpringCloud之前,我以为SpringCloud是与Double一样,只是个单纯的RPC框架.但在今天的学习中,我发现并非如此,事实上,SpringCloud是多个框架的集合,感觉Spr ...

  2. ehcache、memcache、redis三大缓存比较

    最近项目组有用到这三个缓存,去各自的官方看了下,觉得还真的各有千秋!今天特意归纳下各个缓存的优缺点,仅供参考!  Ehcache 在Java项目广泛的使用.它是一个开源的.设计于提高在数据从RDBMS ...

  3. Servlet开发(3)

    Servlet开发 Servlet过滤器: 主要是对访问主页的用户进行过滤,通过登录系统进入的用户可以看到主页内容,在session中存在currentuser. 可以对此进行判断: package ...

  4. HAProxy教程收集

    市面上HA的教程不是很多,基本都是基于LVS+HA实践的打包资料. 要最权威的文档应该去官方. 官方文档入口: http://www.haproxy.org/#docs 中文文档收集: http:// ...

  5. JFileChooser 中文API

    javax.swing类 JFileChooser java.lang.Object java.awt.Component java.awt.Container javax.swing.JCompon ...

  6. Android GIS开发系列计划

    本系列博客的整理与写作计划如下,计划3个月(至2018.2)完成. 第一部分, 入门季 第二部分, Android基础季 第三部分, Data Flow 季 第四部分, 可视化季 第五部分, GIS常 ...

  7. 实现日、周、月排行统计 sql

    在如今很多系统中,都需要进行日.周.月排行统计,但是在网上寻找 了一番,发现很多都是相对的周.月排行,即周排行则用当前时间减去7天.这样我个人认为并不恰当.如月排行中,假设今天是4月22日,则从3月2 ...

  8. JAVA进阶-网络编程

    >通过套接字连接server Socket指代套接字 >读取随意站点的首页 --------- /** * @author Lean @date:2014-10-9 */ public c ...

  9. 【智能家居篇】wifi网络结构(下)

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢. 因为WIFI网络具有移动性,同一时候WIFI以无线电波作为传输媒介,这样的媒介本质上是开放的,且easy被拦截,不论 ...

  10. NYOJ 496 [巡回赛-拓扑排序]

    链接:click here 题意: 巡回赛 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 世界拳击协会(WBA)是历史最悠久的世界性拳击组织,孕育了众多的世界冠军, ...