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. 搭建openfire Android 客户端学习和开发【二】spark源码导入eclipse

    首先声明下 这是我在eoe上转载的 写的很好就摘抄了... 第一步 下载源码 svn下载,下载地址:spark:http://svn.igniterealtime.org/svn/repos/spar ...

  2. 如何在Linux命令行中创建以及展示演示稿

    导读 你在准备一场演讲的时候,脑海可能会先被图文并茂.形象华丽的演示图稿所占据.诚然,没有人会否认一份生动形象的演讲稿所带来的积极作用.然而,并非所有的演讲都需要TED Talk的质量.更多时候,演讲 ...

  3. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  4. HDOJ 2097

    #include<stdio.h> int func(int n,int k) { ; a=n; ) { b+=a%k; a=a/k; } return b; } int main() { ...

  5. linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )

    在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作. 其实shell内置一系列操作符号,可以达到类似效果,大家知道,使用内部操作符会省略 ...

  6. css+div绝对定位

    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" ...

  7. DP:Space Elevator(POJ 2392)

    太空电梯 题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高. 这题就是1742的翻版,对ai排个序就可以 ...

  8. Greedy:Packets(POJ 1017)

    装箱问题1.0 题目大意:就是一个工厂制造的产品都是正方形的,有1*1,2*2,3*3,4*4,5*5,6*6,高度都是h,现在要包装这些物品,只能用6*6*h的包装去装,问你怎么装才能使箱子打到最小 ...

  9. codeforces B. Xenia and Spies 解题报告

    题目链接:http://codeforces.com/problemset/problem/342/B 题目意思:有n个spy,编号从1-n,从左到右排列.现在的任务是,spy s要把信息传递到spy ...

  10. 【wireshark】打开后显示There are no interfaces on which a capture can be done

    解决方式:用管理员方式打开wireshark即可