题目链接:https://www.luogu.org/problemnew/show/P3796

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
#define ll long long
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define P pair<int,int>
const int N=1e6+;
const int mod=1e9+;
void read(int &a)
{
a=;
int d=;
char ch;
while(ch=getchar(),ch>''||ch<'')
if(ch=='-')
d=-;
a=ch-'';
while(ch=getchar(),ch>=''&&ch<='')
a=a*+ch-'';
a*=d;
}
void write(int x)
{
if(x<)
putchar(),x=-x;
if(x>)
write(x/);
putchar(x%+'');
}
struct note
{
int next;
int to[];
int bz;
}trie[N];
int tot;
struct node
{
int sum,pos;
}ans[];
bool cmp(node x,node y)
{
if(x.sum!=y.sum)
return x.sum>y.sum;
else
return x.pos<y.pos;
}
string s[];
inline void clean(int x)
{
trie[x].next=;
trie[x].bz=;
memset(trie[x].to,,sizeof(trie[x].to));
}
inline void ins(string s,int k)
{
int len=s.length();
int now=;
for(re int i=;i<len;i++)
{
int x=s[i]-;
if(!trie[now].to[x])
trie[now].to[x]=++tot,clean(tot);
now=trie[now].to[x];
}
trie[now].bz=k;
}
inline void built()
{
queue <int> q;
for(re int i=;i<=;i++)
if(trie[].to[i])
trie[trie[].to[i]].next=,q.push(trie[].to[i]);
while(!q.empty())
{
int p=q.front();
q.pop();
for(re int i=;i<=;i++)
{
if(trie[p].to[i])
trie[trie[p].to[i]].next=trie[trie[p].next].to[i],q.push(trie[p].to[i]);
else
trie[p].to[i]=trie[trie[p].next].to[i];
}
}
}
inline void solve(string s)
{
int len=s.length();
int now=;
for(re int i=;i<len;i++)
{
int x=s[i]-;
now=trie[now].to[x];
for(re int t=now;t;t=trie[t].next)
ans[trie[t].bz].sum++;
}
}
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
tot=;
clean();
for(re int i=;i<=n;i++)
{
cin>>s[i];
ans[i].sum=;
ans[i].pos=i;
ins(s[i],i);
}
trie[].next=;
built();
cin>>s[];
solve(s[]);
sort(ans+,ans++n,cmp);
cout<<ans[].sum<<endl;
cout<<s[ans[].pos]<<endl;
for(re int i=;i<=n;i++)
{
if(ans[i].sum==ans[i-].sum)
cout<<s[ans[i].pos]<<endl;
else
break;
}
}
return ;
}

AC自动机模板2的更多相关文章

  1. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  2. Match:Keywords Search(AC自动机模板)(HDU 2222)

    多模匹配 题目大意:给定很多个字串A,B,C,D,E....,然后再给你目标串str字串,看目标串中出现多少个给定的字串. 经典AC自动机模板题,不多说. #include <iostream& ...

  3. HDU 3065 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...

  4. HDU 2896 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...

  5. HDU 2222(AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...

  6. HDU 2222 (AC自动机模板题)

    题意: 给一个文本串和多个模式串,求文本串中一共出现多少次模式串 分析: ac自动机模板,关键是失配函数 #include <map> #include <set> #incl ...

  7. hdu 2222 Keywords Search ac自动机模板

    题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #inclu ...

  8. KMP与AC自动机模板

    HDU 1711 Number Sequence(KMP模板题) http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<bits/std ...

  9. HDU3695(AC自动机模板题)

    题意:给你n个字符串,再给你一个大的字符串A,问你着n个字符串在正的A和反的A里出现多少个? 其实就是AC自动机模板题啊( ╯□╰ ) 正着query一次再反着query一次就好了 /* gyt Li ...

  10. POJ2222 Keywords Search AC自动机模板

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:给出一些单词,求多少个单词在字符串中出现过(单词表单词可能有相同的,这些相同的单词视为不同的分别计数 ...

随机推荐

  1. JavaBean 和 pojo 的区别

    JavaBean 是一种JAVA语言写成的可重用组件.它的方法命名,构造及行为必须符合特定的约定: 这个类必须有一个公共的缺省构造函数. 这个类的属性使用getter和setter来访问,其他方法遵从 ...

  2. Redis一次数据丢失

    一台Redis服务器,4核,16G内存且没有任何硬件上的问题.持续高压运行了大约3个月,保存了大约14G的数据,设置了比较完备的Save参数.而就是这台主机,在一次重起之后,丢失了大量的数据,14G的 ...

  3. PHP链接MySQL,查询数据库内容,删除数据库内容。。。记住链接公式!!!

    //扩展类叫MySQLi MySQL是数据库,MySQLi是扩展 Id地址本地网络服务器的地址localhost 如果想链接别人的输入他的服务器id地址. //root代表的是数据库名, //poss ...

  4. [No0000170]Spring Boot慢速入门

    Spring的实例化Bean有三种方式: 使用类构造器直接实例化 使用静态工厂的方法实例化 使用实例工厂方法实例化 <?xml version="1.0" encoding= ...

  5. ReactNative小笔记

    import React, { Component } from 'react'; import { AppRegistry, View } from 'react-native'; export d ...

  6. 如何使用ffmpeg

    https://blog.csdn.net/minger1202/article/details/52468986  解码 https://www.jianshu.com/p/c6cfe2edd083 ...

  7. iOS 模拟器运行不能联网 PAC Fetch failed with error

    app在模拟器是哪个启动成功会自动连接服务器,然后Xcode控制台报错, 模拟器 PAC Fetch failed with error [NSURLErrorDomain:-1001] 这类问题有好 ...

  8. 2015年蓝桥杯省赛A组c++第3题

    /* 小明发现了一个奇妙的数字.它的平方和立方正好把0~9的10个数字每个用且只用了一次. 你能猜出这个数字是多少吗? 请填写该数字,不要填写任何多余的内容. */ #include<cstdi ...

  9. 安装graphlab伤透了心,终于搞定了

    为了方便研究各种机器学习算法,我想用graphlab来辅助我对后续算法的研究.所以我的目标就是安装graphlab到我的windows笔记本中.而基于python的graphlab的安装最好是采用如下 ...

  10. jquery.axios无刷新机制删除

    思路:无刷新机制就是不用的刷新动作 ,用前端html语法删除和后端的数据库删,同时删除达到效果 除操作,来实现无刷洗的方法