POJ2752(next原理理解)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 15536 | Accepted: 7862 |
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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=;
char s[MAXN];
int next[MAXN];
int len;
void getnext()
{
int i=,k=-;
next[]=-;
while(i<len)
{
if(k==-||s[i]==s[k])
{
i++;
k++;
next[i]=k;
}
else k=next[k];
}
}
int num[MAXN],cnt;
int main()
{
while(gets(s))
{
cnt=;
len=strlen(s);
getnext();
int k=len;
num[cnt++]=len;
while(next[k]!=)
{
k=next[k];
num[cnt++]=k;
}
for(int i=cnt-;i>;i--)
printf("%d ",num[i]);
printf("%d\n",num[]);
} return ;
}
POJ2752(next原理理解)的更多相关文章
- JUC回顾之-ConcurrentHashMap源码解读及原理理解
ConcurrentHashMap结构图如下: ConcurrentHashMap实现类图如下: segment的结构图如下: package concurrentMy.juc_collections ...
- POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7406 Accepted: 3363 Description C ...
- java的classLoader原理理解和分析
java的classLoader原理理解和分析 学习了:http://blog.csdn.net/tangkund3218/article/details/50088249 ClassNotFound ...
- js 闭包原理理解
问题?什么是js(JavaScript)的闭包原理,有什么作用? 一.定义 官方解释:闭包是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 很显然 ...
- kalman filter卡尔曼滤波器- 数学推导和原理理解-----网上讲的比较好的kalman filter和整理、将预测值和观测值融和
= 参考/转自: 1 ---https://blog.csdn.net/u010720661/article/details/63253509 2----http://www.bzarg.com/p/ ...
- debug 调试原理理解
引言: 昨天,看了一篇文章,很受启发,记得之前听别的人远程调试过代码,觉得很神奇,在自己程序里打断点,连接远程服务器,开启调试后可以调用远程方法来看数据的输入和输出,不需要查找问题,重新部署,测试问题 ...
- shiro的原理理解
1.shiro原理图如下: 框架解释: subject:主体,可以是用户也可以是程序,主体要访问系统,系统需要对主体进行认证.授权. securityManager:安全管理器,主体进行认证和授权都 ...
- JAVA 1.7并发之LinkedTransferQueue原理理解
昨天刚看完BlockingQueue觉得好高级啊,今天扫到1.7就发现了升级版.... 如果对内容觉得不够充分,可以去看http://www.cs.rochester.edu/u/scott/pape ...
- Redis集群的离线安装以及原理理解
一.本文主要是记录一下Redis集群在linux系统下离线的安装步骤,毕竟在生产环境下一般都是无法联网的,Redis的集群的Ruby环境安装过程还是很麻烦的,涉及到很多的依赖的安装,所以写了一个文章来 ...
随机推荐
- SqlServer查询语句中用到的锁
前段时间**公司DBA来我们这培训.讲了一大堆MYSQL的优化. QA环节一程序员问“SQL语句中的 with nolock 除了不锁表外,是否能读其他锁住的数据". 讲课的人嘟嘟了半天没解 ...
- Linux基础(3)- 正文处理命令及tar命令、vi编辑器、硬盘分区、格式化及文件系统的管理和软连接、硬连接
一.正文处理命令及tar命令 1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件1.txt(覆盖) 2) 将用户信息数据库文件和用户密码数据库文件纵向合并为一个文件2.txt(追加) ...
- React学习之常用概念
看见一篇不错的文章转载,文章源地址:https://blog.csdn.net/zwp438123895/article/details/69374940 一. State和 Props state ...
- mysql创建还原点
set autocommit = 0; insert into t1(name) values ("user1"); savepoint p1; insert into t ...
- POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]
Language: Default Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 19321 ...
- Integrate NSX into Neutron
NSX is VMware's strategy for Software-defined networking, it was implemented purely in software, and ...
- Java RESTful 框架
[转载] 最好的8个 Java RESTful 框架 - 2015 Top 8 Java RESTful Micro Frameworks – Pros/Cons - 2017 Restlet - f ...
- C++正则表达式笔记之wregex
遍历所有匹配 #include <iostream> #include <regex> using namespace std; int main() { wstring ws ...
- PPTP&L2TP&PPPOE client and server configure
一. PPPOE 1. server(参考http://laibulai.iteye.com/blog/1171898) (1)安装rp-pppoe:yum install rp-pppoe (2)配 ...
- PAT 天梯赛 L2-008. 最长对称子串 【字符串】
题目链接 https://www.patest.cn/contests/gplt/L2-008 思路 有两种思路 第一种 遍历每一个字符 然后对于每一个 字符 同时 往左 和 往右 遍历 只要 此时 ...