找到最长串

然后进行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;
}

HDU - 6208 The Dominator of Strings n次KMP 2017 ACM/ICPC Asia Regional Qingdao Online相关推荐

  1. HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)...

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...

  2. HDU 6194 String String String (后缀数组+线段树, 2017 ACM/ICPC Asia Regional Shenyang Online)

    Problem 求字符串 S 中严格出现 k 次的子串个数 k≥1k\ge 1 |S|≤105|S|\le 10^5 ∑|S|≤2×106\sum |S| \le 2\times 10^6 Idea ...

  3. HDU 6208 The Dominator of Strings AC自动机

    题目链接:HDU 6208 The Dominator of Strings Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 65535 ...

  4. hdu 6208 The Dominator of Strings

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6208 题意:给出n个字符串,判断某一个字符串是否包含了其他所有字符串. 分析:首先这个字符串一定是最长的那 ...

  5. HDU 6208 The Dominator of Strings ——(青岛网络赛,AC自动机)

    最长的才可能成为答案,那么除了最长的以外全部insert到自动机里,再拿最长的去match,如果match完以后cnt全被清空了,那么这个最长串就是答案.事实上方便起见这个最长串一起丢进去也无妨,而且 ...

  6. hdu 5023 poj 2777(线段染色)2014 ACM/ICPC Asia Regional 广州 Online

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5023 http://poj.org/problem?id=2777 题意:给出一个长度为N的线段,分 ...

  7. hdu 4283 You Are the One ( dp 2012 ACM/ICPC Asia Regional Tianjin Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意: The TV shows such as You Are the One has been ver ...

  8. HDU 5476 Explore Track of Point 几何题 —— 2015 ACM/ICPC Asia Regional Shanghai Online

    题目见HDU 5476 给出等腰三角形ABC,AB=AC,M为BC中点.P点为三角形内使min{∠MPB+∠APC,∠MPC+∠APB} 最大的点.求P点轨迹. 则容易找到中线AM上的P点都满足使得∠ ...

  9. hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online...

    很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死-- 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了--没了! 反复读题,终于在偶然间 ...

最新文章

  1. No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer解决方法
  2. opencv高效遍历图像
  3. 论文笔记:Autoregressive Tensor Factorizationfor Spatio-temporal Predictions
  4. 【数学】Floating-Point Hazard
  5. vmware虚拟机linux的扩容问题导致redhat无法启动!
  6. java if else 过多_Java利用策略模式优化过多if else代码
  7. Linux 系统 vim 编辑器使用简明教程
  8. Windows给SVN配置中文语言包
  9. 已解决:Multisim仿真出现错误:“发生了仿真错误”“收敛助手”“Transient time point calculation did not converge”
  10. Himall商城ObjectHelper帮助类(1)
  11. 如何规避rm-rf导致的服务器删除问题
  12. cad插件_【CAD插件】家具绘图神器
  13. 担忧:房价八大预言,市场来检验。
  14. 机器人设计之软件设计
  15. 使用codelite搭建stm32开发环境
  16. [Poi2003 ][bzoj 2601]MAL猴子捞月
  17. js 将正则换成字符串的形式,再由字符串转换成正则
  18. Node.js中的异步编程,个人理解及分化讲解
  19. 速度最快的数据库---MEMSQL的安装与部署
  20. html 提示安装flash插件,flashplayer播放插件无法安装解决方案

热门文章

  1. 骑马与砍杀是用python编的_哇咔咔工作室:py基础教程贴
  2. 虚拟服务器好不好,共享虚拟主机好不好
  3. 上海车展直击:哈弗大狗掀起全民追“狗”潮
  4. python绘制女孩_如何借助 Python 俘获女孩子芳心?
  5. 武林风云之数据库插入
  6. 罗马复兴开源代码_社区主导的开源复兴
  7. H.266/VVC帧内预测总结
  8. 库存台帐报表存储过程
  9. [Windows]Win10关于Sysprep无法验证你的Windows安装
  10. ES term之大小写