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 ...
随机推荐
- apache 日志中记录代理IP以及真实客户端IP
vim /usr/local/apach2/conf/httpd.conf 默认情况下log日志格式为:LogFormat "%h %l %u %t \"%r\" %&g ...
- js 创建html元素 渲染html元素
var p1 = document.getElementById('p1'); //添加的元素类型及属性var newNode = document.createElement("input ...
- Makefiles 介绍
http://www-personal.umich.edu/~ppannuto/writings/makefiles.html Makefiles Makefiles (or, the GNU aut ...
- OA、CRM、ERP之间的区别和联系是什么?
我们假设你是某机械行业的销售,一切从今天你收到公司的邮件,去上海参加展会开始 因为 去展会 所有 首先 你打开 OA 登陆 填写出差申请表 送交主管审批 填表--审批--行政订票酒店 然后呢 你飞去上 ...
- codeforces #330 div2
A: #include<cstdio> #include<algorithm> #include<cmath> #include<map> #inclu ...
- commands - `ls`
list only directories: ls -d /path/to/*/
- 2015.4.8-C#入门基础(二)
初来乍道,下面分享一下,自己做的小程序 主要用到 数组,类型转换,枚举,循环: 主要体现的是: 输入姓名,就可以查看其性格 using System;using System.Collections. ...
- multiprocessing跨平台锁的使用(Windows问题)
在Windows上可能遇到,开启的子进程不会关闭的问题 参考multiprocessing官方文档: Explicitly pass resources to child processes On U ...
- POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence
两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...
- Linux文件解压缩详解
tar命令 我们知道在Windows下最常见的压缩文件就只有两种,一是,zip,另一个是.rar.可是Linux就不同了,它有.gz..tar.gz.tgz.bz2..Z..tar等众多的压缩文件名, ...