(KMP)Seek the Name, Seek the Fame -- poj --2752
http://poj.org/problem?id=2752
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14611 | Accepted: 7320 |
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
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stack>
using namespace std; #define N 1000007
#define max(a,b) (a>b?a:b) int Next[N];
char S[N]; void FindNext(int Slen)
{
int i=, j=-;
Next[] = -; while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{ while(scanf("%s", S)!=EOF)
{
int Slen, n; Slen = strlen(S);
n = Slen;
FindNext(Slen); stack<int>Q; while(n)
{
Q.push(Next[n]);
n = Next[n];
} Q.pop();
while(Q.size())
{
printf("%d ", Q.top());
Q.pop();
} printf("%d\n", Slen);
}
return ;
}
(KMP)Seek the Name, Seek the Fame -- poj --2752的更多相关文章
- poj2406 Power Strings(kmp)
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...
- 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的简单应 ...
- Seek the Name, Seek the Fame(Kmp)
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (J ...
- Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)
题意: 就是求前缀和后缀相同的那个子串的长度 然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的 这就是拓展kmp板题嘛... 求出extend数组后 把exten ...
- 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 ...
- (转)python文件操作 seek(),tell()
seek():移动文件读取指针到指定位置 tell():返回文件读取指针的位置 seek()的三种模式: (1)f.seek(p,0) 移动当文件第p个字节处,绝对位置 (2)f.seek(p,1) ...
- POJ 2406 Power Strings(KMP)
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- LightOJ 1258 Making Huge Palindromes(KMP)
题意 给定一个字符串 \(S\) ,一次操作可以在这个字符串的右边增加任意一个字符.求操作之后的最短字符串,满足操作结束后的字符串是回文. \(1 \leq |S| \leq 10^6\) 思路 \( ...
- codeM编程大赛E题 (暴力+字符串匹配(kmp))
题目大意:S(n,k)用k(2-16)进制表示1-n的数字所组成的字符串,例如S(16,16)=123456789ABCDEF10: 解题思路: n最大50000,k最大100000,以为暴力会超时. ...
随机推荐
- 【337】Text Mining Using Twitter Streaming API and Python
Reference: An Introduction to Text Mining using Twitter Streaming API and Python Reference: How to R ...
- Implementing On Item Click / Double Click for TListView
ListView.On Item Click & ListView.On Item Double Click To be able to locate the clicked (if ther ...
- JavaScript 累加求和练习 函数
输入一个数,求从1加到这个数的和 主要代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...
- SpringCloud——Eureka服务注册和发现
一.SpringCloud和Dubbo SpringCloud整合了一套较为完整的微服务解决方案框架,而Dubbo只是解决了微服务的几个方面的问题. content Dubbo SpringCloud ...
- hdoj3038(带权并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:对于给定的a1..an,通过询问下标x..y,给出a[x]+...+a[y],但给出的值可 ...
- 87. Scramble String (String; DP)
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- RMQ(或运算)
RMQ https://ac.nowcoder.com/acm/contest/283/J 题目描述 按位或运算:处理两个长度相同的二进制数,两个相应的二进位中只要有一个为1,该位的结果值为1.例如5 ...
- day4:vcp考试
Q61. Which two statements are true regarding Virtual SAN Fault Domains? (Choose two.)A. They enable ...
- 22-maven-安装与配置
转载:https://blog.csdn.net/wy727764020/article/details/80595451 Maven的安装以及eclipse中配置maven 2018年06月06日 ...
- discuz模板引擎语法
论坛的首页模板:forum/discuz.htm 版块的内容模板:forum/forumdisplay.htm 主题的查看模板:forum/viewthread.htm 帖子的内容模板:forum/p ...