HDU 5880 Family View
$AC$自动机。
用$AC$自动机匹配一次,开一个$flag$记录一下以$i$位置为结尾的最长要打$*$多少个字符,然后倒着扫描一次就可以输出了。
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<stack>
- #include<bitset>
- #include<iostream>
- using namespace std;
- typedef long long LL;
- const double pi=acos(-1.0),eps=1e-;
- void File()
- {
- freopen("D:\\in.txt","r",stdin);
- freopen("D:\\out.txt","w",stdout);
- }
- template <class T>
- inline void read(T &x)
- {
- char c=getchar(); x=;
- while(!isdigit(c)) c=getchar();
- while(isdigit(c)) {x=x*+c-''; c=getchar();}
- }
- const int maxn=;
- int flag[maxn];
- char buf[maxn];
- struct Trie
- {
- int next[maxn][],fail[maxn],end[maxn],Len[maxn];
- int root,L;
- int newnode()
- {
- for(int i = ;i < ;i++) next[L][i] = -;
- Len[L]= end[L] = ; L++;
- return L-;
- }
- void init()
- {
- L = ;
- root = newnode();
- }
- void insert(char buf[])
- {
- int len = strlen(buf);
- int now = root;
- for(int i = ;i < len;i++)
- {
- if(next[now][buf[i]-'a'] == -)
- next[now][buf[i]-'a'] = newnode();
- now = next[now][buf[i]-'a'];
- }
- end[now]++;
- Len[now]=strlen(buf);
- }
- void build()
- {
- queue<int>Q;
- fail[root] = root;
- for(int i = ;i < ;i++)
- if(next[root][i] == -)
- next[root][i] = root;
- else
- {
- fail[next[root][i]] = root;
- Q.push(next[root][i]);
- }
- while( !Q.empty() )
- {
- int now = Q.front();
- Q.pop();
- for(int i = ;i < ;i++)
- if(next[now][i] == -)
- next[now][i] = next[fail[now]][i];
- else
- {
- fail[next[now][i]]=next[fail[now]][i];
- Q.push(next[now][i]);
- }
- }
- }
- void query(char buf[])
- {
- int len = strlen(buf);
- int now = root;
- int res = ;
- for(int i = ;i < len;i++)
- {
- int sign;
- if(buf[i]>='A'&&buf[i]<='Z') sign=buf[i]-'A';
- else if(buf[i]>='a'&&buf[i]<='z') sign=buf[i]-'a';
- else { now=root; continue; }
- now = next[now][sign];
- int temp = now;
- while( temp != root )
- {
- flag[i]=max(flag[i],Len[temp]);
- temp = fail[temp];
- }
- }
- }
- };
- Trie ac;
- int main()
- {
- int T,n; scanf("%d",&T);
- while( T-- )
- {
- scanf("%d",&n); ac.init();
- for(int i = ;i < n;i++)
- { scanf("%s",buf); ac.insert(buf); }
- ac.build();
- getchar(); gets(buf); memset(flag,,sizeof flag);
- ac.query(buf);
- int leng=strlen(buf); int num=;
- for(int i=leng-;i>=;i--)
- {
- num=max(num,flag[i]);
- if(num==) continue;
- else buf[i]='*', num--;
- }
- printf("%s\n",buf);
- }
- return ;
- }
HDU 5880 Family View的更多相关文章
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- hdu 5880 AC自动机
Family View Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)
题意:按要求输出.第一列是表示第几行.每行仅仅能有16个字节的字母,第二列是16进制的ASCII码.第三列大写和小写转换 思路:纯模拟,注意字母的十六进制是2位 #include <iostre ...
- AC自动机及KMP练习
好久都没敲过KMP和AC自动机了.以前只会敲个kuangbin牌板子套题.现在重新写了自己的板子加深了印象.并且刷了一些题来增加自己的理解. KMP网上教程很多,但我的建议还是先看AC自动机(Trie ...
- 2016 年青岛网络赛---Family View(AC自动机)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...
- hdu5880 Family View
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5880 题目: Family View Time Limit: 3000/1000 MS (Ja ...
- hdu 4967 Handling the Past
hdu 4967 Handling the Past view code//把时间离散化,维护一个线段(线段l到r的和用sum[l,r]表示),pop的时候就在对应的时间减一,push则相反 //那么 ...
- HDU 1495 非常可乐
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=103711#problem/M /*BFS简单题 链接地址: http://acm.hdu ...
- 爆零后的感受外加一道强联通分量HDU 4635的题解
今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...
随机推荐
- Asycn/Await 异步编程初窥(二)
经过总过4天的学习和实践,做完了 WinForm 下 .Net 4.5 的基本异步应用,实现了一个 Http 协议下载的测试程序,为以后使用 .Net 4.5 积累知识和经验.这个小程序完成这样几个作 ...
- ASP.NET MVC企业开发的基本环境
ASP.NET MVC企业开发的基本环境[资源服务器概念] 学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang 茗洋 EasyUI1.3.4 ...
- js的onclick和jquery的bind事件执行先后顺序
近期在项目中为每一个ajax触发按钮写正在加载的效果,用的是bootstarp 代码如下 $(function(){ $('.btn').bind('click',function(e){ var $ ...
- SSH的整合
SSH的整合 struts2和hibernate的配置我这里就不多说了,先把两个有关的东西说下.一个是所有的包.struts2+hibernate3+spring2.5我包准备放上去给大家下载. ht ...
- Android_NDK问题:APP_BUILD_SCRIPT points to an unknown file: <project_path>/jni/Android.mk
问题详情: Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: <path>/jni/Android.mk ...: ...
- VC 编程ANSI环境下读写Unicode文件
没有注意到文件编码的不同会产生这么多的问题,在动手以前查询了很多资料,在本博客中收藏了不少先辈的成果,在这里一并表示致敬! 关于ANSI和Unicode编码的原理在这里也不说了,主要讲下如 ...
- Arduino 各种模块篇 震动模块 vibrator
vibrator is a good thing. it has multi-funtionality . :) Now the vibrator we choose is the one whic ...
- Yellow
Yellow这首歌让我知道了yellow这个单词出了黄色的意思外,还有胆怯的,懦弱的意思~~~ 它是Coldplay 的歌曲,歌词很简单,但是有着莫名的忧伤感,值得一提的是这首歌的MV,一个长镜头给出 ...
- Web 请求响应原理(转)
用Java实现Web服务器 减小字体 增大字体 摘要:WWW的工作基于客户机/服务器计算模型,由Web 浏览器(客户机)和Web服务器(服务器)构成,两者之间采用超文本传送协议(HTTP)进行通信,H ...
- Cocos2d-x 截图功能
2.x-3.x版本 //获取屏幕尺寸 CCSize size = CCDirector::sharedDirector()->getWinSize ...