poj2752Seek the Name, Seek the Fame
Description
Step1. Connect the father's name and the mother's name, to a new string S. Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).
Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)
Input
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
Output
Sample Input
ababcababababcabab
aaaaa
Sample Output
2 4 9 18
1 2 3 4 5
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std; char s[];
int next[],l;
void f(int t)
{
if(t == ) return;
f(next[t]);
if(t!=l)printf("%d ",t);
else printf("%d\n",t);
} int main()
{
int i,j,k;
while(scanf("%s",s+)!=EOF)
{
l = strlen(s+);
next[] = ;
for(i = ;i<l+;i++)
{
int t = next[i-];
while(t&&s[i]!=s[t+]) t = next[t];
if(s[i] == s[t+]) t++;
next[i] = t;
}
f(l);
}
return ;
}
poj2752Seek the Name, Seek the Fame的更多相关文章
- poj2752seek the name, seek the fame【kmp】
The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the l ...
- poj2752Seek the Name, Seek the Fame(next数组)
题目传送门 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2439 ...
- POJ--2752--Seek the Name, Seek the Fame【KMP】
链接:http://poj.org/problem? id=2752 题意:对于一个字符串S,可能存在前n个字符等于后n个字符,从小到大输出这些n值. 思路:这道题加深了对next数组的理解.next ...
- 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 ...
- POJ 2752 Seek the Name, Seek the Fame
传送门 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14761 Accepted: 7407 Description ...
- poj-------------(2752)Seek the Name, Seek the Fame(kmp)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11831 Ac ...
- 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 ...
- 【POJ2752】【KMP】Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- poj2752 Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
随机推荐
- onvif规范的实现:server端Discovery实现,通过OnvifTestTool12.06测试
说明:网上关于ONVIF开发的文章并不多,也更找不到具体的实例来入门学习.只能靠翻阅各种Specification摸索中前进,下面是最近几天的成果.调通了服务端(或者说设备端)的Discovery,使 ...
- CSS的base文件常用代码
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body,but ...
- 如何安装chrome扩展,以json-handle
读取本地json文件 chrome插件安装 方式一,在线安装 直接插到json-handle地址,添加即可 https://chrome.google.com/webstore/detail/json ...
- JavaWeb限流QPS简易框架
Java Web利用filter实现拦截请求,统计信息.并控制单台机器QPS. /** * 网络流量控制器 */ public class TrafficFilter implements Filte ...
- YouTube视频插入Markdown
举个例之: 正常YouTube会生成一个<iframe>直接在HTML里面引用即可: <iframe width="420" height="315&q ...
- Ubuntu配置OpenGL环境
建立基本编译环境 sudo apt-get install build-essential 安装OpenGL Library sudo apt-get install libgl1-mesa-dev ...
- MVC 分页获取数据 及点选按钮
@model PagedList<Lyxm.Entity.Suggestion>@using Webdiyer.WebControls.Mvc <div> <ul ...
- nginx上传模块—nginx upload module-
一. nginx upload module原理 官方文档: http://www.grid.net.ru/nginx/upload.en.html Nginx upload module通过ngin ...
- 无法关闭的QT程序——思路开阔一下,原来这么简单!
做一个无法关闭的QT程序(想关闭时要在任务管理器里关闭),看似很难, 其实它并不难,只要让程序在关闭时启动它自身就可以了. 上代码: #include <QtGui> class Temp ...
- 在QTableView中使用各种自定义委托
QT的MVC(View/Delegate)模型十分强大,可以利用各种控件来对表格的输入进行限制,不过我以前一直没有过,这几天研究了一下,写个小例子,希望大家喜欢. 如果看不懂这个例子,请先看QT的自带 ...