题目链接: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. MySQL主从复制介绍

    MySQL主从复制介绍 MySQL数据库的主从复制方案,和使用scp/rsync等命令进行的文件级别复制类似,都是数据的远程传输,只不过MySQL的主从复制是其自带的功能,无需借助第三方工具,而且,M ...

  2. 在移动端如何用swiper实现导航栏效果

    我们在写移动端的时候会有滑动和点击导航后滑动到目标页面功能:而这个功能如果自己写的话会很麻烦,所以我在这推荐一下swiper这个插件. 其实swiper中的官网中也有这种功能的实现,但是我认为是有点麻 ...

  3. Java学习者论坛【申明:来源于网络】

    学习者论坛[申明:来源于网络] 1.Java学习者论坛 2.51论坛 3.csdn论坛 4.JAVA ME论坛 地址|: http://www.javaxxz.com/ 地址|: http://bbs ...

  4. Kindle2018 一周使用报告

    使用2018年年末刚刚发布的KPW有一周时间了,可以借这个机会来对这部设备做一个使用报告了. 那咱们就参考如下描述吧: 1.轻薄便携:6英寸的屏幕,11.6厘米*16.7厘米的机身尺寸,加上仅有8.2 ...

  5. tensorRT使用python进行网络定义

  6. Java的四种内部类(含代码实例)

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  7. 待选框、目标框select项目左右移动

    效果: 可以用一般的select multiple="multiple".自己写jq定义左移.右移.全部左移.全部右移.保存submit后端来操作select属性,方法参考html ...

  8. 压缩维度oj P1173+P1174+P1164

    今天在洛谷上刷dp,忽然冒出一道求最大字段和的问题,然后忘了瞬间忘了这是dp,几分钟一个贪心出来了成功ac,忽然想起自己在作dp,于是乖乖刷dp. 这个可能很多人都会但是今天有4种解法哦,本人只尝试了 ...

  9. ORACLE network environment

    监听程序 建立网络连接 要建立客户机或中间层连接,Oracle Net要求客户机 下列事项: 运行监听程序的主机 监听程序监视的端口 监听程序使用的协议 监听程序处理的服务名 Hostname/ip ...

  10. LeetCode 922 Sort Array By Parity II 解题报告

    题目要求 Given an array A of non-negative integers, half of the integers in A are odd, and half of the i ...