//暴力,从每一行的开始处开始寻找要查询的字符
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; char str[]; int main(){
while(gets(str)){
for(int i=; str[i]; ++i)
if(str[i]=='A'){
if(strstr(str+i, "Apple") == str+i)
printf("MAI MAI MAI!\n");
}
else if(str[i]=='i'){
if(strstr(str+i, "iPhone") == str+i || strstr(str+i, "iPod") == str+i || strstr(str+i, "iPad") == str+i)
printf("MAI MAI MAI!\n");
}
else if(str[i]=='S')
if(strstr(str+i, "Sony") == str+i)
printf("SONY DAFA IS GOOD!\n");
}
return ;
}
 //将要匹配的字符串(也就是题目中查询文本中出现的5个单词)建立trie树,然后生成AC_自动机.....
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std; int trie[][];
int vis[], fail[];//vis标记的是单词的末尾字符所在的节点
char str[][] = {"Apple", "iPhone", "iPod", "iPad", "Sony"};
int cnt;
void buildT(){
for(int i=; i<; ++i){
int u=;
for(int j=; str[i][j]; ++j){
if(trie[u][str[i][j]] == )
trie[u][str[i][j]] = ++cnt;
u=trie[u][str[i][j]];
}
vis[u]=;
}
} void getFail(){
queue<int>q;
for(int i=; i<; ++i)
if(trie[][i]) q.push(trie[][i]);
while(!q.empty()){
int u = q.front();
q.pop();
int v;
for(int i=; i<; ++i)
if(v = trie[u][i]){
fail[v] = trie[fail[u]][i];
q.push(v);
}
else
trie[u][i] = trie[fail[u]][i];
}
} void getText(char *ch){
int u=;
for(int i=; ch[i]; ++i){
int v = trie[u][ch[i]];
u=v;
while(v){
if(vis[v] && (ch[i]=='d' || ch[i]=='e'))
printf("MAI MAI MAI!\n");
else if(vis[v] && ch[i]=='y')
printf("SONY DAFA IS GOOD!\n");
v = fail[v];
}
}
} char text[]; int main(){
buildT();
getFail();
while(gets(text)){
getText(text);
}
return ;
}

2014 网选 5007 Post Robot(暴力或者AC_自动机(有点小题大作了))的更多相关文章

  1. 2014 网选 上海赛区 hdu 5047 Sawtooth

    题意:求n个'M'型的折线将一个平面分成的最多的面数! 思路:我们都知道n条直线将一个平面分成的最多平面数是 An = An-1 + n+1 也就是f(n) = (n*n + n +2)/2 对于一个 ...

  2. 2014 网选 5024 Wang Xifeng's Little Plot

    题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...

  3. 2014 网选 广州赛区 hdu 5025 Saving Tang Monk(bfs+四维数组记录状态)

    /* 这是我做过的一道新类型的搜索题!从来没想过用四维数组记录状态! 以前做过的都是用二维的!自己的四维还是太狭隘了..... 题意:悟空救师傅 ! 在救师父之前要先把所有的钥匙找到! 每种钥匙有 k ...

  4. 2014 网选 广州赛区 hdu 5023 A Corrupt Mayor's Performance Art

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...

  5. 2014 网选 5011 Game(Nim游戏,数学题)

    /* 题意:Nim游戏! 思路:通过异或,判断将n个数表示成二进制的形式之后,是否对应位的数字1 的个数是偶数! */ #include<iostream> using namespace ...

  6. 2014 网选 5012 Dice(bfs模板)

    /* 题意:就是给定两个筛子,每个筛子上6个面,每个面的数字属于[1,6], 且互不相同! 问a筛子最少经过按照题目规定的要求转动,达到和b筛子上下左右前后的数字相同! 思路:很直白的bfs,将每一种 ...

  7. 2014 网选 5014 Number Sequence(异或)

    /* 题意:a, b两个序列,规定由[0, n]区间的数! 求 a[i] ^ b[i] 的和最大! 思路:如果数字 n的二进制有x位, 那么一定存在一个数字m,使得n^m的所有二进制位 都是1,也就是 ...

  8. BUPT复试专题—网络传输(2014网研)

    题目描述 网络的高效互联与智能传输是提升海量用户服务请求映射效率的重要措施.在这个任务中,你需耍在最小的传输时间内,将数据源传输到指定的网络节点中.我们给定的网络一共包含N个节点,其中节点1为数据源. ...

  9. BUPT复试专题—进程管理(2014网研)

    题目描述 在操作系统中,进程管理是非常重要的工作.每个进程都有唯一的进程标识PID.每个进程都可以启动子进程,此时我们称该它本身是其子进程的父进程.除PID为0的进程之外,每个进程冇且只冇一个父进程. ...

随机推荐

  1. 如何提交docker镜像到DockerHub

    Write a Dockerfile In detail: FROM(指定基础image) 构建指令,必须指定且需要在Dockerfile其他指令的前面.后续的指令都依赖于该指令指定的image.FR ...

  2. android: 播放音频

    在 Android 中播放音频文件一般都是使用 MediaPlayer 类来实现的,它对多种格式的音 频文件提供了非常全面的控制方法,从而使得播放音乐的工作变得十分简单.下表列出了 MediaPlay ...

  3. 解决.Net 4.0 A potentially dangerous Request.Form value was detected from the client 异常

    在web.config中加入 <httpRuntime maxRequestLength="22000" executionTimeout="43200" ...

  4. 【原】MyEclipse8.5集成Tomcat7时启动错误:Exception in thread “main” java.lang.NoClassDefFoundError

    解决方法: MyEclipse->Window->Preferences->MyEclipse->Servers->Tomcat->Tomcat 6.x->L ...

  5. SNMP远程监控进程信息的OID

    最近有个项目需要用snmp远程监控进程信息.于是我查了一下资料. 一.资料 .1.3.6.1.2.1.25.4.2.1.1.iso.org.dod.internet.mgmt.mib-2.host.h ...

  6. how to read from __consumer_offsets topic

    来自:http://grokbase.com/t/kafka/users/15bs2r0m83/kafka-0-8-2-1-how-to-read-from-consumer-offsets-topi ...

  7. OpenCV】透视变换 Perspective Transformation(续)

    载分 [OpenCV]透视变换 Perspective Transformation(续) 分类: [图像处理] [编程语言] 2014-05-27 09:39 2776人阅读 评论(13) 收藏 举 ...

  8. 《CSS 设计指南》学习笔记 一

    本篇文章是对这几天看完 Charles Wyke-Smit 的 <CSS 设计指南> 后的一些学习笔记与心得,笔者好像是大一的时候开始接触网页设计,由于并不是计算机专业的,所以所有都是自己 ...

  9. Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学

    B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...

  10. 计算空间直线与平面的交点 (C#)

    public class NGlbVec3d    {// 三维点        public double x, y, z;        public NGlbVec3d()        {   ...