(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,以为暴力会超时. ...
随机推荐
- Axel与Wget下载工具
Axel工具是linux下的http/ftp中强大下载工具,支持多线程和断点续传下载.且可以从多个地址或者从一个地址的多个连接来下载同一个文件. 常用的选项: [root@wjoyxt ~]# axe ...
- ResponseUtil数据传递至前端
package com.java1234.util; import java.io.OutputStream; import java.io.PrintWriter; import javax.ser ...
- Unity 所有特殊文件夹
1.Editor 2.Editor Default Resources Editor Default Resources注意中间是有空格的,它必须放在Project视图的根目录下,如果你想放在/xxx ...
- oracle 查看被锁的表和解锁
相关视图 SELECT * FROM v$lock;SELECT * FROM v$sqlarea;SELECT * FROM v$session;SELECT * FROM v$process ;S ...
- java script btoa与atob的
javascript原生的api本来就支持,Base64,但是由于之前的javascript局限性,导致Base64基本中看不中用.当前html5标准正式化之际,Base64将有较大的转型空间,对于H ...
- Spring Boot logback
前言 今天来介绍下spring Boot如何配置日志logback,我刚学习的时候,是带着下面几个问题来查资料的,你呢 如何引入日志? 日志输出格式以及输出方式如何配置? 代码中如何使用? 正文 Sp ...
- Java8 Stream语法详解 2
1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...
- CentOS7.0重置Root的密码 (忘记密码)
首先进入开启菜单,按下e键进入编辑现有的内核,如下图所示 然后滚动列表,找到ro,将它替换成rw,并加上init=/sysroot/bin/sh,最终变为如下图 然后按CTRL+X进入到单用户模式,在 ...
- hdoj1069 Monkey and Banana(DP--LIS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 思路: 由题意,显然一种block可能有6种形式,且一种形式最多使用一次,因此最多有30×6=1 ...
- nyoj86-找球号(一) 【set 二分查找 hash】
http://acm.nyist.net/JudgeOnline/problem.php?pid=86 找球号(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 ...