【Kmp】Blue Jeans POJ
来源:互联网 发布:天刀无缺染色数据 编辑:程序博客网 时间:2024/06/05 07:25
Link:http://poj.org/problem?id=3080
//#include <bits/stdc++.h>#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;typedef long long LL;/*题意:找出n个串中最长的公共串,并且要求字典序最大题解:枚举第一字符串的子串*/const int N = 66;int nex[N];void getnext(string s){ memset(nex,0,sizeof(nex)); int len = s.length(); nex[0] = -1; int k = -1; for(int i = 1; i < len; i++){ while(k!=-1 && s[k+1]!=s[i]) k = nex[k]; if(s[k+1]==s[i]) k++; nex[i] = k; }}bool Kmp(string s,string p){ int len = s.length(); int lenp = p.length(); int k = -1; for(int i = 0; i < len; i++){ while(k!=-1 && p[k+1]!=s[i]) k = nex[k]; if(p[k+1]==s[i]) k++; if(k == lenp-1) return true; } return false;}struct asd{ string s;}ans[N],now[N*N],aa[N];bool cmp(asd a, asd b){ if(a.s.length() != b.s.length()) return a.s.length() > b.s.length(); return a.s < b.s;}int init(){ int len = aa[0].s.length(); int k = 0; for(int leg = 3; leg <= len; leg++){ for(int i = 0; i+leg <= len; i++) now[k++].s = aa[0].s.substr(i,leg); } return k;}int main(){ int T; scanf("%d",&T); while(T--){ int n; cin >> n; for(int i = 0; i < n; i++) cin >> aa[i].s; int k = init(); sort(now,now+k,cmp); int f = 0; for(int i = 0; i < k; i++) { //cout <<now[i].s << endl; getnext(now[i].s); int flag = 0; for(int j = 1; j < n; j++){ if(!Kmp(aa[j].s,now[i].s)) flag = 1; } if(!flag) { f = 1; cout << now[i].s << endl; break; } } if(!f) cout << "no significant commonalities" << endl; } return 0;}
阅读全文
0 0
- 【Kmp】Blue Jeans POJ
- POJ 3080 Blue Jeans KMP
- POJ 3080 Blue Jeans----kmp
- POJ 3080 Blue Jeans(KMP)
- POJ 3080 Blue Jeans KMP
- poj 3080 Blue Jeans(KMP)
- poj-3080 Blue Jeans(KMP)
- [poj 3080]Blue Jeans [kmp]
- POJ 3080 Blue Jeans KMP
- poj 3080 Blue Jeans kmp+枚举
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans (KMP)
- poj 3080 Blue Jeans ( 二分 + kmp)
- POJ 3080 Blue Jeans KMP+暴力
- poj 3080 Blue Jeans(KMP)
- POJ 3080 Blue Jeans KMP解法
- poj 3080 Blue Jeans(数据结构:KMP)
- 现代前端技术解析:前端项目与技术实践
- Java值传递(基本数据类型和引用数据类型)和虚拟机内存作用
- Python爬虫---处理HTTPS请求 SSL证书验证
- Redis源码解析3
- Unity3D之UI按键绑定事件(四)
- 【Kmp】Blue Jeans POJ
- 判断是否为AVL树~
- HDU 6058 枚举 Kanade's sum
- hdu 1428 漫步校园(搜索+记忆化搜索)
- uva188 Perfect Hash
- 一图读懂:Type-C的前生今世 众接口已哭晕
- CSDN自定义博客栏目实现搜索本站
- Python自然语言处理——nltk_data
- MATLAB画图必备知识