题目传送门

 /*
题意:求出一个串的前缀与后缀相同的字串的长度
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. Django:(7)auth用户认证组件 & 中间件

    用户认证组件 用户认证组件: 功能:用session记录登陆验证状态 前提:用户表:django自带的auth_user 创建超级用户的命令: python manage.py createsuper ...

  2. 元祖、hash了解、字典、集合

    元祖: 元组跟列表差不多,也是存一组数,只是它一旦创建,便不能再修改,所以又叫只读列表. 创建: names = ('neo', 'mike', 'eric') 特性: # 1.可存放多个值 # 2. ...

  3. Servlet的调试

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/debugging.html: 测试/调试Servlet始终是困难的.Servlets往往涉及大量 ...

  4. json序列化后的是字符串,不是二进制。是字符串!!!确定不是二进制!!!

    1.现有一个自定义对象需要储存到sql数据库中去.这个对象里面属性很多,甚至包含一些元素量打到几十万的List集合属性.本人试着使用JSON序列化这个对象,储存到数据库,报maxjsonlength超 ...

  5. MapReduce获取分片数目

    问题 MapReduce Application中mapper的数目和分片的数目是一样的,可是分片数目和什么有关呢? 默认情况下.分片和输入文件的分块数是相等的.也不全然相等,假设block size ...

  6. 使用Maven对JAVA程序打包-带主类、带依赖

    使用Maven对JAVA程序打包-带主类.带依赖 http://blog.csdn.net/strongyoung88/article/details/54097830

  7. UVa 1531 - Problem Bee

    题目:如图所看到的的蜂巢型的图中.蜜蜂想从A点飞到B点,假设A与B不在同一个正六边形中, 则它先飞到A的中心.每次飞到相邻格子的中心,最后飞到B的中心,再飞到B点: 假设在一个格子中.直接飞过去就可以 ...

  8. hdu 3006 The Number of set(思维+壮压DP)

    The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. bug统计分析续(一)基于SQL的Bug统计方法

    本文由 @lonelyrains 出品.转载请注明出处. 文章链接: http://blog.csdn.net/lonelyrains/article/details/44225533 上一篇为 bu ...

  10. Android系统之路(初识MTK) ------ OTA打包ROM安装系统img等到ZIP

    在做OTA升级包的时候,我编译了好多次都没过.老是IO异常.刚開始以为是我 make 的错误.后来多次检查 Error 发现是我的配置信息写错了,与驱动project师一起检查源代码, 改动配置信息后 ...