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 - 文件读写操作 总结

    在android中的文件放在不同位置,它们的读取方式也有一些不同. 本文对android中对资源文件的读取.数据区文件的读取.SD卡文件的读取及RandomAccessFile的方式和方法进行了整理. ...

  2. HDU 4857 逃生 (优先队列+反向拓扑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 解题报告:有n个点,有m个条件限制,限制是像这样的,输入a  b,表示a必须排在b的前面,如果不 ...

  3. Linux zabbix 配置注意事项

    发现php-fpm启动之后,找不到 php-fpm.pid文件??? vi php-fpm.conf 去掉里面那个 pid = run/php-fpm.pid 前面的分号然后再启动php-fpm才能自 ...

  4. NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)

    Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求 ...

  5. LInux 安全测试

    [CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...

  6. linux之eval用法(高级bash程序员的必修之技)

    1. eval command-line 其中command-line是在终端上键入的一条普通命令行.然而当在它前面放上eval时,其结果是shell在执行命令行之前扫描它两次.如: pipe=&qu ...

  7. recv和send函数

    转自  http://www.cnblogs.com/blankqdb/archive/2012/08/30/2663859.html 1. send解析 sockfd:指定发送端套接字描述符. bu ...

  8. django LDAP

    > http://goodosoft.github.io/2015/02/25/Using-AD-as-authentication-for-Django/ > http://my.osc ...

  9. 3.django笔记之form表单

    作者:刘耀 瞎copy伸手党 我在诅咒你. Django的form的作用: 1.生成html标签 2.用来做用户提交的验证 3.可以和models一起使用(modelform) 一.form基础 工程 ...

  10. codeforces A. Dima and Continuous Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...