HDU 1403 Longest Common Substring
来源:互联网 发布:sql数据修复工具 编辑:程序博客网 时间:2024/06/09 18:36
Problem Description
Given two strings, you have to tell the length of the Longest Common Substring of them.
For example:
str1 = banana
str2 = cianaic
So the Longest Common Substring is "ana", and the length is 3.
For example:
str1 = banana
str2 = cianaic
So the Longest Common Substring is "ana", and the length is 3.
Input
The input contains several test cases. Each test case contains two strings, each string will have at most 100000 characters. All the characters are in lower-case.
Process to the end of file.
Process to the end of file.
Output
For each test case, you have to tell the length of the Longest Common Substring of them.
Sample Input
bananacianaic
Sample Output
3后缀数组的应用
#include<iostream>#include<cmath>#include<map>#include<vector>#include<queue>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 200005;class suffix{private:char s[maxn];int r[maxn], w[maxn], ss[maxn], h[maxn];int sa[maxn], rk[maxn + maxn], size, bit = 256;int size1;public:bool get(){ if (scanf("%s", s + 1) != 1) return false;size1 = strlen(s + 1);scanf("%s", s + size1 + 2);s[++size1] = 1;size = strlen(s + 1);return true;}void pre(){memset(rk, 0, sizeof(rk));for (int i = 1; i <= bit; i++) w[i] = 0;for (int i = 1; i <= size; i++) w[(int)s[i]]++;for (int i = 1; i <= bit; i++) w[i] += w[i - 1];for (int i = size; i; i--) sa[w[(int)s[i]]--] = i;for (int i = 1, j = 1; i <= size; i++)rk[sa[i]] = (s[sa[i]] == s[sa[i + 1]] ? j : j++);for (int j = 1; j < size; j += j){for (int i = 1; i <= size; i++) w[i] = 0;for (int i = 1; i <= size; i++) w[rk[i + j]]++;for (int i = 1; i <= size; i++) w[i] += w[i - 1];for (int i = size; i; i--) ss[w[rk[i + j]]--] = i;for (int i = 1; i <= size; i++) w[i] = 0;for (int i = 1; i <= size; i++) w[rk[ss[i]]]++;for (int i = 1; i <= size; i++) w[i] += w[i - 1];for (int i = size; i; i--) sa[w[rk[ss[i]]]--] = ss[i];for (int i = 1, k = 1; i <= size; i++)r[sa[i]] = (rk[sa[i]] == rk[sa[i + 1]] && rk[sa[i] + j] == rk[sa[i + 1] + j]) ? k : k++;for (int i = 1; i <= size; i++) rk[i] = r[i];}for (int i = 1, k = 0, j; i <= size; h[rk[i++]] = k)for (k ? k-- : 0, j = sa[rk[i] - 1]; s[i + k] == s[j + k]; k++);}void work(){int mid = (size1 - 1) >> 1;for (int l = 0, r = size1 - 1,f; l < r;){f = 0;for (int i = 2, j; i <= size; i = j + 1){int f1 = 0, f2 = 0;for (j = i; h[j] >= mid; j++){if (sa[j] < size1) f1 = 1; else f2 = 1;if (sa[j - 1] < size1) f1 = 1; else f2 = 1;if (f1 && f2) { f = 1; goto end; }}}end:;if (f) l = mid; else r = mid - 1;mid = (l + r) >> 1;if (mid == l) mid = r;}printf("%d\n", mid);}}f;int main(){while (f.get()){f.pre();f.work();}return 0;}
0 0
- HDU 1403 Longest Common Substring
- HDU 1403 Longest Common Substring
- hdu-1403-Longest Common Substring
- HDU 1403 Longest Common Substring
- HDU 1403 Longest Common Substring
- HDU 1403 Longest Common Substring
- HDU - 1403 Longest Common Substring
- HDU 1403 Longest Common Substring 【 后缀数组】
- hdu 1403 Longest Common Substring - 后缀数组
- hdu 1403 Longest Common Substring (后缀数组)
- hdu 1403 Longest Common Substring (后缀数组模板题)
- hdu 1403 Longest Common Substring(求公共子串长度)
- hdu 1403 Longest Common Substring (后缀数组模板)
- hdu 1403 Longest Common Substring 后缀数组da算法
- HDU 1403 Longest Common Substring(后缀数组入门)
- 【后缀数组】 HDOJ 1403 Longest Common Substring
- Longest common substring
- spoj1811 Longest Common Substring
- .Net网络编程——服务端获取客户端连接
- [CentOS]CentOS7安裝SSH教學
- Android 获取本地外网IP、内网IP、计算机名等信息
- BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 Splay
- FILE
- HDU 1403 Longest Common Substring
- 树莓派 - 架设花生壳
- hadoop环境配置2--jdk配置
- SQL Server查詢未提交事務,終止進程,解除表鎖
- Java-----4、流程控制和数组
- mfc 彻底关闭窗口进程
- GMM 说话人识别 Maltab 框架
- Codeforces 534D - Handshakes(构造,暴力)
- android中ShareSDK使用步骤