一定好好学SAM。。。模板在此:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
using namespace std;
const int maxn=+,sig=;
struct SAM{
struct node{
int len;node*p,*tx[sig];
}sam[maxn<<],*nodecnt,*root,*x;
void init(){nodecnt=sam;return;}
node*newnode(int len=){node*t=nodecnt++;t->len=len;return t;}
void extend(int pos,char ch){
int c=ch-'a';node*p=x;x=newnode(pos+);
for(;p&&!p->tx[c];p=p->p) p->tx[c]=x;
if(!p) x->p=root;
else{ node*q=p->tx[c];
if(q->len==p->len+) x->p=q;
else{ node*r=newnode();
r[]=q[];r->len=p->len+;q->p=x->p=r;
for(;p&&p->tx[c]==q;p=p->p) p->tx[c]=r;
}
} return;
}
void build(char*s){x=root=newnode();for(int i=;s[i];i++)extend(i,s[i]);return;}
int query(char*t){
int len=strlen(t),ans=;node*p=root;
for(int i=,L=;i<len;i++){
int c=t[i]-'a';
if(p->tx[c])L++,p=p->tx[c];
else{
for(;p&&!p->tx[c];p=p->p);
if(p) L=p->len+,p=p->tx[c];
else p=root,L=;
} ans=max(L,ans);
} return ans;
}
}sol;
inline int read(){
int x=,sig=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')sig=-;ch=getchar();}
while(isdigit(ch))x=*x+ch-'',ch=getchar();
return x*=sig;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
char s[maxn],t[maxn];
void init(){
scanf("%s%s",s,t);
sol.init();sol.build(s);write(sol.query(t));
return;
}
void work(){
return;
}
void print(){
return;
}
int main(){init();work();print();return ;}

注意一个copy的写法:r[0]=q[0];似乎就不用写一个copy函数了?(雾

POJ 2774 最长公共子串的更多相关文章

  1. poj 2774 最长公共子串 后缀数组

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 25752   Accepted: 10 ...

  2. poj 2774 最长公共子--弦hash或后缀数组或后缀自己主动机

    http://poj.org/problem?id=2774 我想看看这里的后缀数组:http://blog.csdn.net/u011026968/article/details/22801015 ...

  3. 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774

    Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...

  4. POJ 2774 Long Long Message [ 最长公共子串 后缀数组]

    题目:http://poj.org/problem?id=2774 Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total ...

  5. 后缀数组(模板题) - 求最长公共子串 - poj 2774 Long Long Message

    Language: Default Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 21 ...

  6. poj 2774 后缀数组 两个字符串的最长公共子串

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 31904   Accepted: 12 ...

  7. poj 2774 Long Long Message,后缀数组,求最长公共子串 hdu1403

    题意:给出两个字符串,求最长公共子串的长度. 题解:首先将两个字符串连在一起,并在中间加一个特殊字符(字串中不存在的)切割,然后两个串的最长公共字串就变成了全部后缀的最长公共前缀.这时就要用到heig ...

  8. POJ 2774 Long Long Message (二分 + Hash 求最长公共子串)题解

    题意:求最长公共子串 思路:把两个串Hash,然后我们把短的作为LCS的最大可能值,然后二分长度,每次判断这样二分可不可以.判断时,先拿出第一个母串所有len长的子串,排序,然后枚举第二个母串len长 ...

  9. POJ 2217 (后缀数组+最长公共子串)

    题目链接: http://poj.org/problem?id=2217 题目大意: 求两个串的最长公共子串,注意子串是连续的,而子序列可以不连续. 解题思路: 后缀数组解法是这类问题的模板解法. 对 ...

随机推荐

  1. animation的6个属性

    @keyframes 规定动画.   animation 所有动画属性的简写属性,除了 animation-play-state 属性.   animation-name 规定 @keyframes ...

  2. phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置

    下载了个phpmyadmin最新版本的,始终显示这样的内容,求助.如何解决哈?>缺少 mysqli 扩展.请检查 PHP 配置. <a href="Documentation.h ...

  3. Linq101-Set

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Set { / ...

  4. 基于laravel4.2的相关架构设计

    项目组不久前引进了laravel框架,本人参与了laravel的调研和项目架构设计.个人认为项目架构中基于laravel的有些设计还是比较实用和有借鉴性的,现将一些设计分享给大家,希望能和大家共同学习 ...

  5. asp.net Request.ServerVariables[] 读解

    获取客户端的IP地址,代码如下: /// <summary> /// 获取客户端IP地址 /// </summary> /// <returns></retu ...

  6. (转)PHP数组的总结(很全面啊)

    一.什么是数组数组就是一组数据的集合,把一系列数据组织起来,形成一个可操作的整体.数组的每个实体都包含两项:键和值. 二.声明数据在PHP中声明数组的方式主要有两种:一是应用array()函数声明数组 ...

  7. Android之ListView/GridView 优化

    一.效率最低的getView实现 我们知道,ListView和GridView的显示都是通过Adapter的getView实现的. ListView/GridView数据量较小时,我们的处理方式一般是 ...

  8. 带A圈的秘密

    真嗒安全策略的罗罗,,害的我和其他的不一样.

  9. Swift - 14 - 字符串的基础操作

    //: Playground - noun: a place where people can play import UIKit // 拼接 var str = "Hello, playg ...

  10. 修路方案(nyoj)

    算法:次小生成树 描述 南将军率领着许多部队,它们分别驻扎在N个不同的城市里,这些城市分别编号1~N,由于交通不太便利,南将军准备修路. 现在已经知道哪些城市之间可以修路,如果修路,花费是多少. 现在 ...