HDU
来源:互联网 发布:coc 女王升级数据 编辑:程序博客网 时间:2024/06/05 15:11
找到最长串
然后进行n次KMP
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#include <sstream>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;const int maxn = 500000 + 7, INF = 0x3f3f3f3f;int T, n;string a[maxn], s;int max_;void solve() { for(int i = 0; i < n; ++i) { int ok = 0; int m = (int)a[i].size(); int f[m+3] ; string p = a[i]; f[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 j = 0; for(int i = 0; i < max_; ++i) { while(j && s[i] != p[j]) j = f[j]; if(s[i] == p[j]) j++; if(j == m) { ok = 1; break;} } if(!ok) { cout << "No\n"; return; } } cout << s << "\n";}int main() { ios::sync_with_stdio(0); std::cin.tie(0); cin >> T; while(T--) { cin >> n; max_ = 0; for(int i = 0; i < n; ++i) { cin >> a[i]; if((int)a[i].size() > max_) { max_ = (int)a[i].size(); s = a[i]; } } solve(); } return 0;}
阅读全文
1 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 理解 Python 语言中的 defaultdict
- Mac环境下Angular CLI配置
- uva 839 紫书例题及代码理解
- hadoop案例分析(二)
- oracle 表查询总结
- HDU
- codeforces 858 A k-rounding(数学)
- Eclipse下maven使用嵌入式(Embedded)Neo4j创建Hello World项目
- 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数
- c语言 ---- Stack实现
- 什么是跨域?
- Android移动开发-通过手势实现翻页效果
- sevlet 给客户端下载一个文件
- Spring Boot基础