博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2774 Long Long Message 后缀数组
阅读量:4584 次
发布时间:2019-06-09

本文共 3608 字,大约阅读时间需要 12 分钟。

Long Long Message
 

Description

The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days: his mother is getting ill. Being worried about spending so much on railway tickets (Byterland is such a big country, and he has to spend 16 shours on train to his hometown), he decided only to send SMS with his mother. 
The little cat lives in an unrich family, so he frequently comes to the mobile service center, to check how much money he has spent on SMS. Yesterday, the computer of service center was broken, and printed two very long messages. The brilliant little cat soon found out: 
1. All characters in messages are lowercase Latin letters, without punctuations and spaces. 
2. All SMS has been appended to each other – (i+1)-th SMS comes directly after the i-th one – that is why those two messages are quite long. 
3. His own SMS has been appended together, but possibly a great many redundancy characters appear leftwards and rightwards due to the broken computer. 
E.g: if his SMS is “motheriloveyou”, either long message printed by that machine, would possibly be one of “hahamotheriloveyou”, “motheriloveyoureally”, “motheriloveyouornot”, “bbbmotheriloveyouaaa”, etc. 
4. For these broken issues, the little cat has printed his original text twice (so there appears two very long messages). Even though the original text remains the same in two printed messages, the redundancy characters on both sides would be possibly different. 
You are given those two very long messages, and you have to output the length of the longest possible original text written by the little cat. 
Background: 
The SMS in Byterland mobile service are charging in dollars-per-byte. That is why the little cat is worrying about how long could the longest original text be. 
Why ask you to write a program? There are four resions: 
1. The little cat is so busy these days with physics lessons; 
2. The little cat wants to keep what he said to his mother seceret; 
3. POJ is such a great Online Judge; 
4. The little cat wants to earn some money from POJ, and try to persuade his mother to see the doctor :( 

Input

Two strings with lowercase letters on two of the input lines individually. Number of characters in each one will never exceed 100000.

Output

A single line with a single integer number – what is the maximum length of the original text written by the little cat.

Sample Input

yeshowmuchiloveyoumydearmotherreallyicannotbelieveityeaphowmuchiloveyoumydearmother

Sample Output

27 题意:   给你两个字符串长度不超过1e5   问你最长公共子串的长度 题解:   百度搜一发后缀数组,资料一大把,看完之后呢,然后弱弱抄板子
#include 
#include
#include
#include
#include
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define ls i<<1#define rs ls | 1#define mid ((ll+rr)>>1)#define pii pair
#define MP make_pairtypedef long long LL;const long long INF = 1e18+1LL;const double Pi = acos(-1.0);const int N = 2e5+10, M = 2e5+20, mod = 1e9+7, inf = 2e9;///heght[i] 表示 Suffix(sa[i-1])和Suffix(sa[i]) 的最长公共前缀:///rank[i] 表示 开头为i的后缀的等级:///sa[i] 表示 排名为i的后缀 的开头位置:int *rank,r[N],sa[N],height[N],wa[N],wb[N],wm[N];bool cmp(int *r,int a,int b,int l) { return r[a] == r[b] && r[a+l] == r[b+l];}void SA(int *r,int *sa,int n,int m) { int *x=wa,*y=wb,*t; for(int i=0;i
=0;--i)sa[--wm[x[i]]]=i; for(int i=0,j=1,p=0;p
=j)y[p++]=sa[i]-j; for(i=0;i
=0;--i)sa[--wm[x[y[i]]]]=y[i]; for(t=x,x=y,y=t,i=p=1,x[sa[0]]=0;i
flag) ans = max(ans,height[i]); } printf("%d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/zxhl/p/5990039.html

你可能感兴趣的文章
类EF框架Chloe.ORM升级:只为更完美
查看>>
c++文件操作
查看>>
nodejs实现新闻爬虫
查看>>
关于left join (本文出处:http://www.cnblogs.com/aces/ )
查看>>
解决WebService 测试窗体只能用于来自本地计算机的请求
查看>>
Linux 用户和用户组详解
查看>>
深入理解DIP、IoC、DI以及IoC容器
查看>>
赋值文件
查看>>
Vue 数组 字典 template v-for 的使用
查看>>
蓝牙模块选择经验谈
查看>>
PAT 1060 爱丁顿数(25)(STL-multiset+思路)
查看>>
进程和线程
查看>>
爬取校花网视频
查看>>
mysql root密码忘记最快方法
查看>>
imagemagick imagick
查看>>
DevOps - 版本控制 - Gitlab
查看>>
代码管理必备-----git使用上传码云
查看>>
静态库Lib和动态库Dll
查看>>
获取日k数据
查看>>
【LOJ】 #2132. 「NOI2015」荷马史诗
查看>>