poj 3080 kmp模板
来源:互联网 发布:淘宝打折网 编辑:程序博客网 时间:2024/06/05 07:33
kmp模板
//#pragma warning (disable: 4786)//#pragma comment (linker, "/STACK:16777216")//HEAD#include <cstdio>#include <ctime>#include <cstdlib>#include <cstring>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <vector>#include <iostream>#include <algorithm>using namespace std;//LOOP#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))#define CPY(a, b) memcpy(a, b, sizeof(a))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)//STL#define SZ(V) (int)V.size()#define PB push_back//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RS(s) scanf("%s", s)//OUTPUT#define WI(n) printf("%d\n", n)#define WS(s) printf("%s\n", s)typedef long long LL;typedef unsigned long long ULL;typedef vector <int> VI;const int INF = 1000000000;const double eps = 1e-10;const int MAXN = 1000000;char a[100][100], b[100];int f[100];int N;set<string>S;int find(char *T, char *P, int *f){ int n = strlen(T); int m = strlen(P); int j = 0; int Maxl = 0; for (int i = 0; i < n; i++) { while (j && P[j] != T[i]) j = f[j]; if (P[j] == T[i]) j++; if (j > Maxl) Maxl = j; } return Maxl;}void getfail(char *P, int *f){ int m = strlen(P); f[0] = 0; f[1] = 0; for (int i = 1; i < m; i++) { int j = f[i]; while (j && P[i] != P[j]) j = f[j]; f[i + 1] = P[i] == P[j] ? j + 1 : 0; }}int main (){ int T; RI(T); while (T--) { RI(N); RS(b); S.clear(); REP(i, N - 1) RS(a[i]); int n = strlen(b); int Maxl = 0; int l, r; REP(i, n - Maxl) { int x = 100; getfail(b + i, f); REP(j, N - 1) { int y = find(a[j], b + i, f); x = min(x, y); } if (x != 100 && x > Maxl) { Maxl = x; l = i; r = i + Maxl - 1; } string ss(b + l, b + r); S.insert(ss); } if (Maxl < 3) puts("no significant commonalities"); else { FE(i, l, r) printf("%c",b[i]); printf("\n"); } } return 0;}
0 0
- poj 3080 kmp模板
- 【KMP模板】POJ 3461
- Poj 3461 KMP模板
- KMP模板 POJ 3461 KMP模板讲解
- POJ Oulipo(KMP模板题)
- POJ 3461 Oulipo(KMP模板)
- POJ 3080 Blue Jeans (KMP+暴力枚举)【模板】
- KMP模板题 poj 3461 Oulipo
- poj 3461 Oulipo(kmp 模板题)
- poj 2752 kmp(next数组模板)
- POJ 3461 Oulipo(KMP模板)
- 【哈希&KMP模板题】-POJ-3461-Oulipo
- POJ 3461 Oulipo (kmp模板)
- poj 3461 Oulipo(KMP模板题)
- poj 3461(kmp字符串匹配模板)
- POJ 3461 Oulipo (KMP模板题)
- POJ - 3461 Oulipo(KMP模板题)
- poj 3461 Oulipo (KMP 模板题)
- 通配spring加载hibernate映射方法(.hbm.xml)
- webView使用笔记
- socket通信的多进程编程:
- ARM汇编 .word 解析
- 使用PreparedStatement的execute方法需要注意的问题
- poj 3080 kmp模板
- AFNetworking源码之AFSecurityPolicy模块
- bzoj 1588 splay树入门题
- B BL指令浅析
- 跨域登录
- 设计模式之桥接模式-bridge
- linux虚拟机增加硬盘存储
- Mysql设置自增长主键的初始值
- UIScrollView的基本属性和协议方法