【POJ 2752 Seek the Name, Seek the Fame】
Time Limit: 2000MS
Memory Limit: 65536K
Description
The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm: 
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
The input contains a number of test cases. Each test case occupies a single line that contains the string S described above. 
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000. 
Output
For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.
Sample Input
ababcababababcabab
aaaaa
Sample Output
2 4 9 18
1 2 3 4 5
Source
POJ Monthly--2006.01.22,Zeyuan Zhu
题解:
①题目要求求出一个串的所有和某后缀相等的前缀的长度。
②KMP的NEXT数组递归求解
#include<stdio.h>
#include<cstring>
#define go(i,a,b) for(int i=a;i<=b;i++)
using namespace std;const int N=1000003;
int m,f[N],j,S[N],s;char P[N];
int main()
{
f[0]=f[1]=0;
while(~scanf("%s",P))
{
m=strlen(P);
go(i,1,m-1){j=f[i];while(j&&P[j]!=P[i])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}
j=m;while(j)S[++s]=j,j=f[j];while(s)printf("%d ",S[s--]);puts("");
}
return 0;
}//Paul_Guderian
那年我二十五岁,转眼许多年过去我真的成功了
我的歌传遍了大街小巷,我有了一个家和可爱的女儿,
有了一群志同道合的朋友……————————汪峰《那年我五岁》
【POJ 2752 Seek the Name, Seek the Fame】的更多相关文章
- 【POJ 2752】 Seek the Name, Seek the Fame
		
[题目链接] 点击打开链接 [算法] KMP 沿着失配指针扫一遍即可 [代码] #include <algorithm> #include <bitset> #include ...
 - 【poj 2752】Seek the Name, Seek the Fame(字符串--KMP)
		
题意:给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度. 解法:利用KMP中next[ ]数组的性质,依次找到前缀.后缀匹 ...
 - 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 ...
 - (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 ...
 - 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的简单应 ...
 - KMP POJ 2752 Seek the Name, Seek the Fame
		
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
 - 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(KMP需转换下思想)
		
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10204 Ac ...
 - POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
		
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
 
随机推荐
- idea中使用逆向工程----三部曲
			
逆向工程小伙伴可能都知道,可以根据公司大佬的数据库简单创建实体类和dao接口以及mapper的映射文件,逆向工程可能在数据库字段比较少的时候体现不会方便,但是当参与到数据库字段比较多的时候,我们不可能 ...
 - centos7 多网卡修改默认路由
			
最近在virtualbox里搭了一个centos7的虚拟机,但是网络这一块总是有问题. 单网卡下的问题: 1.当我配置连接方式为NAT网络地址转换的时候,虚拟机可以访问外网.但是在网络地址转换的情况下 ...
 - 数据结构学习-AVL平衡树
			
环境:C++ 11 + win10 IDE:Clion 2018.3 AVL平衡树是在BST二叉查找树的基础上添加了平衡机制. 我们把平衡的BST认为是任一节点的左子树和右子树的高度差为-1,0,1中 ...
 - strak组件(5):为列表定制预留钩子方法
			
效果图: 新增函数 def get_list_display(self): 获取页面上应该显示的列,预留的自定义扩展,例如:以后根据用户的不同显示不同的 一.stark组件 stark/servic ...
 - POJ:3684-Physics Experiment(弹性碰撞)
			
Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3392 Accepted: 1177 Sp ...
 - 笔记-爬虫-js代码解析
			
笔记-爬虫-js代码解析 1. js代码解析 1.1. 前言 在爬取网站时经常会有js生成关键信息,而且js代码是混淆过的. 以瓜子二手车为例,直接请求https://www.guaz ...
 - K-均值聚类——电影类型
			
K-均值聚类 K-均值算法试图将一系列样本分割成K个不同的类簇(其中K是模型的输入参数),其形式化的目标函数称为类簇内的方差和(within cluster sum of squared errors ...
 - Hibernate SQL方言
			
RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS3 ...
 - Android字体大小怎么自适应不同分辨率?
			
今天有人问我,android系统不同分辨率,不同大小的手机,字体大小怎么去适应呢?其实字体的适应和图片的适应是一个道理的. 一. 原理如下: 假设需要适应320x240,480x320分辨率.在res ...
 - react书写规范小记
			
1.对齐方式 //如果没有属性,在自闭和标签前添加一个空格: <Footer /> //如果可以放在一行,放在一行上即可: <Footer bar="bar" / ...