POJ 3729 Facer’s string
来源:互联网 发布:百度人工智能产品 编辑:程序博客网 时间:2024/05/22 18:31
#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 100005#define maxm 400005#define eps 1e-10#define mod 1000000007#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R//#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headint c[maxn];int s[maxn], t1[maxn], t2[maxn], sa[maxn];int rank[maxn], height[maxn];void build(int n, int m){int *x = t1, *y = t2;for(int i = 0; i < m; i++) c[i] = 0;for(int i = 0; i < n; i++) c[x[i] = s[i]]++;for(int i = 1; i < m; i++) c[i] += c[i-1];for(int i = n-1; i >= 0; i--) sa[--c[x[i]]] = i;for(int k = 1; k <= n; k <<= 1) {int p = 0;for(int i = n - k; i < n; i++) y[p++] = i;for(int i = 0; i < n; i++) if(sa[i] >= k) y[p++] = sa[i] - k;for(int i = 0; i < m; i++) c[i] = 0;for(int i = 0; i < n; i++) c[x[y[i]]]++;for(int i = 1; i < m; i++) c[i] += c[i-1];for(int i = n-1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];p = 1, swap(x, y), x[sa[0]] = 0;for(int i = 1; i < n; i++)x[sa[i]] = y[sa[i]] == y[sa[i-1]] && y[sa[i]+k] == y[sa[i-1]+k] ? p-1 : p++;if(p >= n) break;m = p;}}void getheight(int n){int k = 0;for(int i = 0; i <= n; i++) rank[sa[i]] = i;for(int i = 0; i < n; i++) {if(k) k--;int j = sa[rank[i] - 1];while(s[i+k] == s[j+k]) k++;height[rank[i]] = k;}}int n, m, k, len;void read(void){for(int i = 0; i < n; i++) scanf("%d", &s[i]), s[i] += 2;s[n] = 0;for(int i = n+1; i <= n + m; i++) scanf("%d", &s[i]), s[i] += 2;len = n + m + 1;s[len] = 1;}void work(void){build(len + 1, 10005);getheight(len);int t1 = 0, t2 = 0, flag = 0;int ans = 0, res = 0;for(int i = 1; i <= len; i++) {if(height[i] < k) {if(t2) ans += t1;t1 = t2 = flag = 0;}else {if(!flag) {if(sa[i-1] < n) t1++;else t2++;flag = 1;}if(sa[i] < n) t1++;else t2++;}}if(t2) ans += t1;t1 = t2 = flag = 0;for(int i = 1; i <= len; i++) {if(height[i] < k + 1) {if(t2) res += t1;t1 = t2 = flag = 0;}else {if(!flag) {if(sa[i-1] < n) t1++;else t2++;flag = 1;}if(sa[i] < n) t1++;else t2++;}}if(t2) res += t1;printf("%d\n", ans - res);}int main(void){while(scanf("%d%d%d", &n, &m, &k)!=EOF) {read();work();}return 0;}
0 0
- POJ 3729 Facer’s string
- POJ 3729 Facer’s string
- POJ 3729 Facer’s string (后缀数组)
- POJ 3729 Facer’s string 笔记
- POJ 3729 Facer’s string(后缀数组)
- POJ 3729 Facer's string (后缀数组)
- POJ 3729 Facer’s string (后缀数组 两串后缀的LCP为K的对数)
- POJ-3717-Facer's Chocolate Dream
- POJ题目3229 Facer’s string(后缀数组求a串长度为k子串有几个出现在b串)
- POJ 3827 Facer is learning to swim
- String s; String s = null; String s = ""; .intern()
- String s = null ; String s = "" ; String s ;
- 洛谷P2707 Facer帮父亲
- pku3226 String's Puzzle
- zoj2587 Marlon's String
- KMP:Marlon's String
- ZOJ3587 Marlon's String
- AC's String HDU3973
- 第十五周项目二-阅读程序2
- hdu~2795(线段树)
- iOS自定义控件之图像选取按钮
- 学习笔记_CCNx_20141204(1)
- Java并发编程之线程互斥笔记
- POJ 3729 Facer’s string
- mfcc
- C99
- Hadoop快速入门
- 2014年工作中遇到的20个问题:141-160
- 关于Android ADT和SDK更新的问题
- 【BZOJ】【P1030】【JSOI2007】【文本生成器】【题解】【AC自动机】
- Linux启动gdb调试模式二——断点调试
- Hadoop集群搭建