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 ...
随机推荐
- asp.net后台的一些操作
1.在后台绑定下拉框再返回到前台 protected StringBuilder sq = new StringBuilder();//为了在前台绑定 protected void Page_Load ...
- ASP.NET通用权限组件思路设计
开篇 做任何系统都离不开和绕不过权限的控制,尤其是B/S系统工作原理的特殊性使得权限控制起来更为繁琐,所以就在想是否可以利用IIS的工作原理,在IIS处理客户端请求的某个入口或出口通过判断URL来达到 ...
- 查看并设置oracle并发连接数
1.Sql代码1.select count(*) from v$process select count(*) from v$process --当前的数据库连接数2.Sql代码1.select v ...
- jQuery日期和时间插件(jquery-ui-timepicker-addon.js)中文破解版使用
<html> <head> <title></title> <link type="text/css" href=" ...
- mysql数据库 数据类型
char(m) 固定长度字符串,m<=255:处理速度快: varchar(m) 可变长度字符串,m<=255: int(m) 整数型,-214783647到214783648之间,使用u ...
- .Net Service部署(二)
1. 以管理员权限运行cmd.exe2. 安装服务 安装服务需要注意的是,如果电脑已经安装了此服务,需要先停止服务然后删除服务, 在进行安装注册,注册前先运行 cd C:\Windows\Micro ...
- 关于dwt文件和lbi文件
1,dwt 文件是网页模板文件(Dreamweaver Template), 在创建网站的多个网页的时候,通常可以将网页的共同部分创建成为一个模板, 然后给多个网页调用, 以实现网页代码的重复利用. ...
- windows下安装配置Xampp
XAMPP是一款开源.免费的网络服务器软件,经过简单安装后,就可以在个人电脑上搭建服务器环境.本文为大家介绍Windows中安装XAMPP(Apache+Mysql+PHP)及使用方法及其相关问题的总 ...
- Scrapy安装问题
按照说明直接使用pip install scrapy会有两个问题: fatal error: 'ffi.h' file not found fatal error: 'libxml/xmlversio ...
- C语言基础07
结构体与函数的区别: 1.函数是由相同数据类型的变量组成. 2.结构体可以有不同数据类型组合.可以包含char,int,float,数组等类型. struct 结构名称 { 数据类型 成员: 注意 ...