#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct Tree
{
Tree *next[];
bool isVirus;
int num;
};
Tree *root;
int all;
char temp[];
int temps[];
int n,m;
void insert(char temp[],int Num)
{
int len=strlen(temp);
Tree *the=root;
for(int i=; i<len; i++)
{
int temps=temp[i]-' ';
if(the->next[temps]==NULL)
{
Tree* ttemp=(Tree *)malloc(sizeof(Tree));
for(int j=; j<; j++)
ttemp->next[j]=NULL;
ttemp->isVirus=false;
if(i==len-)
{
ttemp->isVirus=true;
ttemp->num=Num;
}
the->next[temps]=ttemp;
}
else if(i==len-)
{
the->next[temps]->isVirus=true;
the->next[temps]->num=Num;
}
the=the->next[temps];
}
}
void search(int num)
{
int virusNum=;
int vir[];
int len=strlen(temp);
for(int i=; i<len; i++)
{
Tree* the=root;
for(int j=; i+j<len; j++)
{
int ttemp=(int)(temp[i+j]-' ');
if(the->next[ttemp]==NULL)break;
else if(the->next[ttemp]->isVirus)
{
bool ok=false;
for(int s=; s<virusNum; s++)
{
if(vir[s]==the->next[ttemp]->num)
ok=true;
}
if(!ok)
{
vir[virusNum++]=the->next[ttemp]->num;
i=i+j;
break;
}
else
the=the->next[ttemp];
}
else
the=the->next[ttemp];
}
if(virusNum==)break;
}
if(virusNum)
{
all++;
printf("web %d:",num);
sort(vir,vir+virusNum);
for(int i=; i<virusNum; i++)
printf(" %d",vir[i]);
printf("\n");
}
}
int main()
{
int virusNum;
int vir[];
root=(Tree *)malloc(sizeof(Tree));
for(int i=; i<; i++)
root->next[i]=NULL;
root->isVirus=false;
cin>>n;
for(int i=; i<=n; i++)
{
scanf("%s",temp);
insert(temp,i);
}
cin>>m;
for(int i=; i<=m; i++)
{
scanf("%s",temp);
search(i);
}
printf("total: %d\n",all);
return ;
}

本题很水,直接字典树可以a掉,不过听说是ac自动机模板题,有学ac自动机的想法,后面也许会贴上ac自动机的代码。

hdu 2896 字典树解法的更多相关文章

  1. HDU 5687 字典树插入查找删除

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...

  2. HDU 5384 字典树、AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...

  3. hdu 2112(字典树+最短路)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  5. Chip Factory HDU - 5536 字典树(删除节点|增加节点)

    题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...

  6. hdu 1251 字典树的应用

    这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...

  7. Repository HDU - 2846 字典树

    题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...

  8. Phone List HDU - 1671 字典树

    题意:给出一堆一组一组的数字  判断有没有哪一个是另外一个的前缀 思路:字典树 插入的同时进行判断  不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含 刚开始 ...

  9. Hat’s Words HDU - 1247 字典树

    题意:给出数个单词 输出单词 如果该单词 是由字典中的单词组成的 思路:字典树 先把全部建树  然后对于每一个单词进行分割,分别拿两半到字典树里面去找 小心RE! #include<bits/s ...

随机推荐

  1. div滚动条弹出层效果 (所需要的css文件和js文件,都已经上传到文件里面了progressbar.rar)

    <%--总的弹出层--%> <div class="tcck" id="joinclub" style="display:none& ...

  2. iOS AudioQueue机制的延迟问题探究

    关键字:VOIP,AudioUnit,AudioQueue,RemoteIO问题描述VOIP通话,iOS底层音频方式采用AudioUnit机制,本来也挺好,但是会有遇到CS域来电时RemoteIO挂死 ...

  3. Python笔记 001

    #python版本:3.5.2 #for循环 for letter in ("xuyingke"): #默认循环 print ("当前字母:",letter) ...

  4. dedecms recommend 注入 exp

    我看没人用python写过发过 所以我就发一下 喜欢用python的就用我这个吧 不喜欢的就用JAR那个或者PHP那个吧 #coding:GBK import  re import urllib &q ...

  5. EDIUS设置3D转场的教程

    当你们学习完了EDIUS 2D转场自定义后,一定也想了解3D是如何自定义的吧!其实用法都差不多,下面就和小编我一起来学习下EDIUS 3D转场自定义设置吧! 1.首先我们还是做好自定义转场的准备工作. ...

  6. Jquery选择器之基本选择器

    id选择器 共同点: text:代表标签之间的文本值 返回值:均为列表 根据给定的ID值匹配一个标签元素,如果id值中有元字符(如 !"#$%&'()*+,./:;<=> ...

  7. Oracle警告、跟踪文件(10046、死锁等跟踪)

    跟踪文件由各个后台进程生成,警报日志中记录关键操作包括:     ·所有启动和关闭命令,包括中间命令,如alter database mount     ·实例的所有内部错误(ORA-600错误,只能 ...

  8. Hibernate5.2之原生SQL查询

    Hibernate5.2之原生SQL查询 一. 介绍  在上一篇博客中笔者通过代码的形式给各位读者介绍了Hibernate中最重要的检索方式--HQL查询.在本博文中笔者将向各位读者介绍Hiberna ...

  9. HTC Vive开发笔记之SteamVR插件集成

    重要组件 SteamVR_Camera VR摄像机,主要功能是将Unity摄像机的画面进行变化,形成Vive中的成像画面 使用方法: l 在任一个摄像机上增加脚本 l 点击Expand按钮 完成以上操 ...

  10. python装饰器示例

    https://wiki.python.org/moin/PythonDecoratorLibrary#Property_Definition