[POJ2774]Long Long Message 解题报告
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 :(
program poj2774;
const maxn=;
var na,nb,m,n,i:longint;
s1,s2:ansistring;
a,height,sa,rank,tmp,s:array[-..maxn]of longint; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end; procedure Suffix_Array;
var i,j,p,size,v0,v1,v00,v01:longint;
begin
size:=max(,n);
for i:= to size- do s[i]:=;
for i:= to n- do rank[i]:=a[i];
for i:= to n- do inc(s[rank[i]]);
for i:= to size- do inc(s[i],s[i-]);
for i:=n- downto do
begin
dec(s[rank[i]]);
sa[s[rank[i]]]:=i;
end;
j:=;
while j<=n do
begin
p:=;
for i:=n-j to n- do
begin
tmp[p]:=i;
inc(p);
end;
for i:= to n- do if sa[i]-j>= then
begin
tmp[p]:=sa[i]-j;
inc(p);
end;
for i:= to size- do s[i]:=;
for i:= to n- do inc(s[rank[i]]);
for i:= to size- do inc(s[i],s[i-]);
for i:=n- downto do
begin
dec(s[rank[tmp[i]]]);
sa[s[rank[tmp[i]]]]:=tmp[i];
end;
p:=;tmp[sa[]]:=;
for i:= to n- do
begin
v0:=sa[i-];v1:=sa[i];
if v0+j<n then v00:=rank[v0+j] else v00:=-;
if v1+j<n then v01:=rank[v1+j] else v01:=-;
if (rank[v0]=rank[v1])and(v00=v01) then tmp[sa[i]]:=p else
begin
inc(p);tmp[sa[i]]:=p;
end;
end;
for i:= to n- do rank[i]:=tmp[i];
j:=j << ;
end;
end; function compare(i,j,x:longint):longint;
begin
while (a[i+x-]=a[j+x-])and(x<=na)and(x<=nb) do inc(x);
exit(x-);
end; procedure calc_height;
var i:longint;
begin
if rank[]= then height[]:= else height[]:=compare(,sa[rank[]-],);
for i:= to n- do
if rank[i]= then height[i]:= else height[i]:=compare(i,sa[rank[i]-],max(height[i-],));
end; function check(x:longint):boolean;
var i,j:longint;
flag1,flag2:boolean;
begin
i:=;
while i<n do
begin
flag1:=false;flag2:=false;
if sa[i]<=na-x then flag1:=true;
if (sa[i]>m)and(sa[i]<=n-x) then flag2:=true;
//控制找到的是真实存在的子串
j:=i+;
while (j<n)and(height[sa[j]]>=x) do
begin
if sa[j]<=na-x then flag1:=true;
if (sa[j]>m)and(sa[j]<=n-x) then flag2:=true;
inc(j);
end;
if flag1 and flag2 then exit(true);
i:=j;
end;
exit(false);
end; procedure binary;
var L,R,mid,ans:longint;
begin
ans:=;
L:=;R:=min(na,nb);
while L<=R do
begin
mid:=(L+R) >> ;
if check(mid) then
begin
ans:=mid;L:=mid+;
end else R:=mid-;
end;
writeln(ans);
end; begin
readln(s1);
na:=length(s1);
for i:= to na- do a[i]:=ord(s1[i+])-;
m:=;
while m<na do m:=m << ;
m:=na-+m;
readln(s2);
nb:=length(s2);
for i:=m+ to m++nb- do a[i]:=ord(s2[i-m])-;
n:=m+nb+;
Suffix_Array;
calc_height;
binary;
end.
[POJ2774]Long Long Message 解题报告的更多相关文章
- URAL 1654 Cipher Message 解题报告
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1654 题意:简单的理解就是,把一个序列中相邻的且是偶数个相同的字符删除,奇数个的话就只保 ...
- 【NOIP2015】提高组D1 解题报告
P1978神奇的幻方 Accepted 描述 幻方是一种很神奇的 N ∗ N 矩阵:它由数字 1,2,3, … … , N ∗ N 构成,且每行.每列及两条对角线上的数字之和都相同. 当 N 为奇数时 ...
- 2011 ACM-ICPC 成都赛区解题报告(转)
2011 ACM-ICPC 成都赛区解题报告 首先对F题出了陈题表示万分抱歉,我们都没注意到在2009哈尔滨赛区曾出过一模一样的题.其他的话,这套题还是非常不错的,除C之外的9道题都有队伍AC,最终冠 ...
- NOIP2015 提高组(senior) 解题报告
过了这么久才来发解题报告,蒟蒻实在惭愧 /w\ Day1 T1 [思路] 模拟 [代码] #include<iostream> #include<cstring> #inclu ...
- 冲刺Noip2017模拟赛5 解题报告——五十岚芒果酱
1. 公约数(gcd) [问题描述] 给定一个正整数,在[,n]的范围内,求出有多少个无序数对(a,b)满足 gcd(a,b)=a xor b. [输入格式] 输入共一行,一个正整数n. [输出格式] ...
- 【LeetCode】91. Decode Ways 解题报告(Python)
[LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
- 二模13day1解题报告
二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...
- BZOJ 1051 最受欢迎的牛 解题报告
题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4438 Solved: 2353[S ...
随机推荐
- 【APUE】Chapter10 Signals
Signal主要分两大部分: A. 什么是Signal,有哪些Signal,都是干什么使的. B. 列举了非常多不正确(不可靠)的处理Signal的方式,以及怎么样设计来避免这些错误出现. 10.2 ...
- 「日常训练」「小专题·图论」Domino Effect(1-5)
题意 分析 这题几乎就是一条dijkstra的问题.但是,如何考虑倒在中间? 要意识到这题求什么:单源最短路的最大值.那么有没有更大的?倒在中间有可能会使它更大. 但是要注意一个问题:不要把不存在的边 ...
- bam文件测序深度统计-bamdst
最近接触的数据都是靶向测序,或者全外测序的数据.对数据的覆盖深度及靶向捕获效率的评估成为了数据质量监控中必不可少的一环. 以前都是用samtools depth 算出单碱基的深度后,用perl来进行深 ...
- Python网络编程(基础总结、 入门经典)
Linux下文件类型: bcd -lsp b(块.设备文件) c(字符设备文件) d(目录) -(普通文件) ...
- 问题 D: 约数的个数
问题 D: 约数的个数 时间限制: 1 Sec 内存限制: 32 MB提交: 272 解决: 90[提交][状态][讨论版][命题人:外部导入] 题目描述 输入n个整数,依次输出每个数的约数的个数 ...
- tinymce4.x 上传本地图片 (转载)
转载自:http://www.cnblogs.com/fhen/p/5809514.html tinymce4.x 上传本地图片 tinymce是一款挺不错的html文本编辑器.但是添加图片是直接 ...
- NO10——各种欧几里得
int gcd(int n,int m)//n>m { //最大公约数 int r; while(m) { r = n%m; n = m; m = r; } return n; } int kg ...
- [整理]docker内部时区修改的两种方法
方法一 终端执行 date命令,查看宿主服务器的时区是否正确 如果正确: 执行 docker cp /etc/localtime 容器ID:/etc/localtime 将本地时间拷贝到docker内 ...
- Android流式布局控件
1,自定义flowlayout代码 package com.hyang.administrator.studentproject.widget; import android.content.Cont ...
- truffle开发一个简单的Dapp
1.安装Truffle:npm install -g truffle 2.建立项目目录并进入:mkdir pet-shop-tutorial cd pet-shop-tutorial 3.使用truf ...