1269. Obscene Words Filter

Time limit: 0.5 second
Memory limit: 8 MB
There is a problem to check messages of web-board visitors for the obscene words. Your elder colleagues commit this problem to you. You are to write a program, which check if there is at least one obscene word from the given list in the given text as a substring.

Input

The first line consists of integer n (1 ≤ n ≤ 10000) — an amount of words. The next n lines contain the list of words that we can’t allow to use in our well-educated society. A word may contain any symbol but the ones with codes 0, 10 and 13. The length of each word doesn’t exceed 10000 symbols. The total list of words doesn’t exceed 100 KB. Then there is an integer m — the number of lines of the text. A size of the text doesn’t exceed 900 KB.

Output

the number of line and the number of position separated with a space, where an obscene word occurs for the first time. If there are no obscene words, output “Passed”.

Sample

input output
5
dear
sweetie
angel
dream
baby
8
Had I the heavens' embroidered cloths,
Enwrought with golden and silver light,
The blue and the dim and the dark cloths
Of night and light and the half-light,
I would spread the cloths under your feet:
But I, being poor, have only my dreams;
I have spread my dreams under your feet;
Tread softly because you tread on my dreams.
6 33
Problem Author: Pavel Atnashev
Problem Source: Ural State University championship, October 25, 2003
Difficulty: 832
 
题意:问在文章中第一次出现禁忌单词的地方
分析:AC自动机,但这题卡时间卡内存
链表?边目录?No,卡时间
数组?对了一半,卡空间
所以,只能动态的分配孩子的空间
 #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define INF (1000000001) const int N = ;
struct TreeType
{
char C;
int Next;
int *Child;
unsigned short Len, CLen, Size;
} Tree[N];
//int First[N], To[N], Next[N], Tot;
int n, m, Cnt, Ans = INF;
char Str[N * ];
int Q[N]; /*inline void Insert(int u, int v)
{
Tot++;
To[Tot] = v, Next[Tot] = First[u];
First[u] = Tot;
}*/ inline void Updata(TreeType &T)
{
T.Size += ;
int *p = new int[T.Size + ];
for(int i = ; i < T.CLen; i++) p[i] = T.Child[i];
delete []T.Child;
T.Child = p;
} inline void Ins(char *Str)
{
int Length = strlen(Str + ), x = , Tab;
bool Flag;
For(i, , Length)
{
Flag = ;
/*for(Tab = First[x]; Tab; Tab = Next[Tab])
if(Tree[To[Tab]].C == Str[i])
{
Flag = 1;
x = To[Tab];
break;
}*/
for(Tab = ; Tab < Tree[x].CLen; Tab++)
if(Tree[Tree[x].Child[Tab]].C == Str[i])
{
Flag = , x = Tree[x].Child[Tab];
break;
}
if(!Flag)
{
//Insert(x, ++Cnt);
if(Tree[x].CLen >= Tree[x].Size) Updata(Tree[x]);
Tree[x].Child[Tree[x].CLen++] = ++Cnt;
Tree[Cnt].C = Str[i], x = Cnt;
}
}
Tree[x].Len = Length;
} inline void Input()
{
scanf("%d", &n);
getchar();
For(i, , n)
{
gets(Str + );
Ins(Str);
}
} inline void Build()
{
int Head = , Tail = ;
int u, v, Tab, k, vv;
//for(Tab = First[0]; Tab; Tab = Next[Tab])
for(Tab = ; Tab < Tree[].CLen; Tab++)
Q[++Tail] = Tree[].Child[Tab];
while(Head <= Tail)
{
u = Q[Head++];
//for(Tab = First[u]; Tab; Tab = Next[Tab])
for(Tab = ; Tab < Tree[u].CLen; Tab++)
{
v = Tree[u].Child[Tab];
if(!v) continue;
//for(k = First[Tree[u].Next]; k; k = Next[k])
for(k = ; k < Tree[Tree[u].Next].CLen; k++)
if(Tree[vv = Tree[Tree[u].Next].Child[k]].C == Tree[v].C)
{
Tree[v].Next = vv;
if(Tree[v].Len < Tree[vv].Len)
Tree[v].Len = Tree[vv].Len;
break;
}
Q[++Tail] = v;
}
}
} inline void Solve()
{
//printf("%d\n", Cnt);
Build();
scanf("%d", &m), getchar();
int Length, x, Tab;
bool Flag;
For(Now, , m)
{
gets(Str + );
Length = strlen(Str + ), x = ;
For(i, , Length)
{
do
{
Flag = ;
//for(Tab = First[x]; Tab; Tab = Next[Tab])
for(Tab = ; Tab < Tree[x].CLen; Tab++)
if(Tree[Tree[x].Child[Tab]].C == Str[i])
{
x = Tree[x].Child[Tab], Flag = ;
break;
}
if(!Flag)
{
x = Tree[x].Next;
continue;
}
if(Tree[x].Len)
{
if(Ans > i - Tree[x].Len + ) Ans = i - Tree[x].Len + ;
}
break;
} while(x); }
if(Ans != INF)
{
printf("%d %d\n", Now, Ans);
return;
}
}
printf("Passed\n");
} int main()
{
freopen("F.in", "r", stdin);
freopen("F.out", "w", stdout);
Input();
Solve();
return ;
}

ural 1269. Obscene Words Filter的更多相关文章

  1. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  2. JavaScript Array -->map()、filter()、reduce()、forEach()函数的使用

    题目: 1.得到 3000 到 3500 之内工资的人. 2.增加一个年龄的字段,并且计算其年龄. 3.打印出每个人的所在城市 4.计算所有人的工资的总和. 测试数据: function getDat ...

  3. JavaWeb——Filter

    一.基本概念 之前我们用一篇博文介绍了Servlet相关的知识,有了那篇博文的知识积淀,今天我们学习Filter将会非常轻松,因为Filter有很多地方和Servlet类似,下面在讲Filter的时候 ...

  4. 以bank account 数据为例,认识elasticsearch query 和 filter

    Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...

  5. AngularJS过滤器filter-保留小数,小数点-$filter

    AngularJS      保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...

  6. 挑子学习笔记:特征选择——基于假设检验的Filter方法

    转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...

  7. [模拟电路] 2、Passive Band Pass Filter

    note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...

  8. AngularJS过滤器filter-时间日期格式-渲染日期格式-$filter

    今天遇到了这些问题索性就 写篇文章吧 话不多说直接上栗子 不管任何是HTML格式还是JS格式必须要在  controller 里面写 // new Date() 获取当前时间 yyyy-MM-ddd ...

  9. 《ES6基础教程》之 map、forEach、filter indexOf 用法

    1,map,对数组的每个元素进行一定操作,返回一个新的数组. var oldArr = [{first_name:"Colin",last_name:"Toh" ...

随机推荐

  1. Android Activity模拟dialog

    Android项目中很多地方,都会弹出一个弹出框.类似于自己定义的alertDialog,比如微信的退出提示,但由于Dialog的限制,可能不能很完美的实现你的想要的功能,所有研究发现他们这种实现其实 ...

  2. LVS负载均衡集群服务搭建详解(一)

    LVS概述 1.LVS:Linux Virtual Server 四层交换(路由):根据请求报文的目标IP和目标PORT将其转发至后端主机集群中的某台服务器(根据调度算法): 不能够实现应用层的负载均 ...

  3. Autolayout及VFL经验分享

    http://www.cocoachina.com/industry/20131108/7322.html 这篇不是什么教程.Cocoa autolayout出来蛮久了.以前多次想去深入研究一下,每次 ...

  4. jlink安装

    https://www.segger.com/jlink-software.html?step=1&file=JLink_510p

  5. Linux下配置Tomcat服务器

    Linux下配置Tomcat服务器和Windows下其实差不多,可以去官网下载安装包释放或者在线下载,只是当时下载的windows.zip文件,现在下载.tar.gz格式的即可,下面使用命令行的方式安 ...

  6. hdu 1098 Lowest Bit 解题报告

    题目链接:http://code.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=22 ...

  7. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  8. July 14th, Week 29th Thursday, 2016

    Risk comes from not knowing what you are doing. 风险常常来自于不知道自己在做什么. What is risk? I think risk means t ...

  9. Linux 中文乱码问题

    弄了好久还是乱码 最终方法:进入 vim /etc/vimrc中 原先只有一个 set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936改成: let ...

  10. js iframe onload &line-height浏览器兼容问题

    1.IE iframe onload事件 在IE下给iframe添加onload事件经常无效,因为在IE下它最多只能被激活一次,而且无论你有多少个iframe,被激活的也只能是最后一个的.可以用下面的 ...