(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,以为暴力会超时. ...
随机推荐
- Access denied for user 'root'@'localhost' (using password:YES)解决方法
Access denied for user 'root'@'localhost' (using password:YES)解决方法 在MySQL的使用过程中,我们可能会碰到“Access denie ...
- Ubuntu下Eclipse热键Ctrl+Alt+Up无效的解决
原文链接 :http://rox.iteye.com/blog/875078 现在好多链接都打不开了, Ubuntu下一直用NetBeans开发,改了热键为Eclipse的,复制行不管用,一直认为是N ...
- mysql mapper中增删查改
//1.增 public int insert(Port port) ; //2.删 public int deleteM(String id);//3.改 public int update(Por ...
- __init__和__new__,以及self
__new__: 每次实例化类的时候会默认先执行__new__,进行实例化类. 如果想改变默认__new__行为,可以对它进行自定义,必须有返回实例. __init__: 对实例化的类进行初始化, ...
- android笔记:ListView及ArrayAdapter
ListView用于展示大量数据,而数据无法直接传递给ListView,需要借助适配器adapter来完成. ArrayAdapter是最常用的adapter,可以通过泛型来指定要适配的数据类型.常见 ...
- Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default
sudo vim /etc/xorg.conf copy: Section "Monitor" Identifier "Monitor0" VendorName ...
- raptor
raptor - 必应词典 美['ræptər]英['ræptə(r)] n.猛禽:攫禽 网络迅猛龙:雷电威龙:决战侏罗纪
- python之socket运用之执行命令
服务端的代码 import socket import subprocess HOST = "127.0.0.1" PORT = 5001 ip_bind = (HOST,PORT ...
- Jmeter元件作用域
转载自飞测团队
- mybatis遍历array数组与集合、json
遍历数组: int saveOptions(@Param("items")String[] items, @Param("questionId")int que ...