题目链接: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. js document.activeElement 获得焦点的元素

    <body> <input type="text" id="test" value="ajanuw"> <sc ...

  2. AJAX里使用的弹窗样式 tanchuang.js tanchuang.css

    tanchuang.js // 每个弹窗的标识 var x =0; var idzt = new Array(); var Window = function(config){ //ID不重复 idz ...

  3. js中if语句的几种优化代码写法

    UglifyJS是一个对javascript进行压缩和美化的工具,在它的文档说明中,我看到了几种关于if语句优化的方法. 一.使用常见的三元操作符 复制代码 代码如下: if (foo) bar(); ...

  4. .NET Core开发日志——HttpClientFactory

    当需要向某特定URL地址发送HTTP请求并得到相应响应时,通常会用到HttpClient类.该类包含了众多有用的方法,可以满足绝大多数的需求.但是如果对其使用不当时,可能会出现意想不到的事情. 博客园 ...

  5. jdbc --- javabean

    第一部分: javaBean 类  要和数据库表的字段一一对应 package com.ljs.bean; public class UserBean { private int id; privat ...

  6. hive优化之开启压缩功能

    1.开启hive作业mapreduce任务中间压缩功能: 对于数据进行压缩可以减少job中map和reduce task间的数据传输量.对于中间数据压缩,选择一个低cpu开销编/解码器要不选择一个压缩 ...

  7. 下载文件的协议:HTTP、FTP、P2P

    本篇学习笔记以HTTP.FTP.P2P叙述与网上下载文件有关的协议 需要掌握的要点: 下载一个文件可以使用 HTTP 或 FTP,这两种都是集中下载的方式,而 P2P 则换了一种思路,采取非中心化下载 ...

  8. 生成树协议(STP)

    首先了解一下环路问题: 两个交换机将两个局域网同时连接起来的时候,不幸地出现了环路: 这两个交换机还是都能够收到广播包的.交换机 A 一开始是不知道机器 2 在哪个局域网的,所以它会把广播消息放到局域 ...

  9. ArcEngine二次开发,TOCControl控件上使用contextMenuStrip

    右键菜单,在二次开发中很实用,以前没用过,最近通过一本书了解到,一直想找这么一个控件来用. 一般的控件,将contextMenuStrip控件拖到所依托的控件上,然后输入自己想要的几个功能.  在所依 ...

  10. [archlinux] linux boot process/order/stage

    信息量好大 --! 神教读物,无人能比: https://wiki.archlinux.org/index.php/Arch_boot_process IBM的高质量文档 https://www.ib ...