$AC$自动机。

用$AC$自动机匹配一次,开一个$flag$记录一下以$i$位置为结尾的最长要打$*$多少个字符,然后倒着扫描一次就可以输出了。

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<stack>
  11. #include<bitset>
  12. #include<iostream>
  13. using namespace std;
  14. typedef long long LL;
  15. const double pi=acos(-1.0),eps=1e-;
  16. void File()
  17. {
  18. freopen("D:\\in.txt","r",stdin);
  19. freopen("D:\\out.txt","w",stdout);
  20. }
  21. template <class T>
  22. inline void read(T &x)
  23. {
  24. char c=getchar(); x=;
  25. while(!isdigit(c)) c=getchar();
  26. while(isdigit(c)) {x=x*+c-''; c=getchar();}
  27. }
  28.  
  29. const int maxn=;
  30. int flag[maxn];
  31. char buf[maxn];
  32.  
  33. struct Trie
  34. {
  35. int next[maxn][],fail[maxn],end[maxn],Len[maxn];
  36. int root,L;
  37. int newnode()
  38. {
  39. for(int i = ;i < ;i++) next[L][i] = -;
  40. Len[L]= end[L] = ; L++;
  41. return L-;
  42. }
  43. void init()
  44. {
  45. L = ;
  46. root = newnode();
  47. }
  48. void insert(char buf[])
  49. {
  50. int len = strlen(buf);
  51. int now = root;
  52. for(int i = ;i < len;i++)
  53. {
  54. if(next[now][buf[i]-'a'] == -)
  55. next[now][buf[i]-'a'] = newnode();
  56. now = next[now][buf[i]-'a'];
  57. }
  58. end[now]++;
  59. Len[now]=strlen(buf);
  60. }
  61. void build()
  62. {
  63. queue<int>Q;
  64. fail[root] = root;
  65. for(int i = ;i < ;i++)
  66. if(next[root][i] == -)
  67. next[root][i] = root;
  68. else
  69. {
  70. fail[next[root][i]] = root;
  71. Q.push(next[root][i]);
  72. }
  73. while( !Q.empty() )
  74. {
  75. int now = Q.front();
  76. Q.pop();
  77. for(int i = ;i < ;i++)
  78. if(next[now][i] == -)
  79. next[now][i] = next[fail[now]][i];
  80. else
  81. {
  82. fail[next[now][i]]=next[fail[now]][i];
  83. Q.push(next[now][i]);
  84. }
  85. }
  86. }
  87. void query(char buf[])
  88. {
  89. int len = strlen(buf);
  90. int now = root;
  91. int res = ;
  92. for(int i = ;i < len;i++)
  93. {
  94. int sign;
  95. if(buf[i]>='A'&&buf[i]<='Z') sign=buf[i]-'A';
  96. else if(buf[i]>='a'&&buf[i]<='z') sign=buf[i]-'a';
  97. else { now=root; continue; }
  98. now = next[now][sign];
  99. int temp = now;
  100. while( temp != root )
  101. {
  102. flag[i]=max(flag[i],Len[temp]);
  103. temp = fail[temp];
  104. }
  105. }
  106. }
  107. };
  108.  
  109. Trie ac;
  110.  
  111. int main()
  112. {
  113. int T,n; scanf("%d",&T);
  114. while( T-- )
  115. {
  116. scanf("%d",&n); ac.init();
  117. for(int i = ;i < n;i++)
  118. { scanf("%s",buf); ac.insert(buf); }
  119. ac.build();
  120.  
  121. getchar(); gets(buf); memset(flag,,sizeof flag);
  122. ac.query(buf);
  123.  
  124. int leng=strlen(buf); int num=;
  125.  
  126. for(int i=leng-;i>=;i--)
  127. {
  128. num=max(num,flag[i]);
  129. if(num==) continue;
  130. else buf[i]='*', num--;
  131. }
  132. printf("%s\n",buf);
  133. }
  134. return ;
  135. }

HDU 5880 Family View的更多相关文章

  1. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  2. hdu 5880 AC自动机

    Family View Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)

    题意:按要求输出.第一列是表示第几行.每行仅仅能有16个字节的字母,第二列是16进制的ASCII码.第三列大写和小写转换 思路:纯模拟,注意字母的十六进制是2位 #include <iostre ...

  4. AC自动机及KMP练习

    好久都没敲过KMP和AC自动机了.以前只会敲个kuangbin牌板子套题.现在重新写了自己的板子加深了印象.并且刷了一些题来增加自己的理解. KMP网上教程很多,但我的建议还是先看AC自动机(Trie ...

  5. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

  6. hdu5880 Family View

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5880 题目: Family View Time Limit: 3000/1000 MS (Ja ...

  7. hdu 4967 Handling the Past

    hdu 4967 Handling the Past view code//把时间离散化,维护一个线段(线段l到r的和用sum[l,r]表示),pop的时候就在对应的时间减一,push则相反 //那么 ...

  8. HDU 1495 非常可乐

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=103711#problem/M /*BFS简单题 链接地址: http://acm.hdu ...

  9. 爆零后的感受外加一道强联通分量HDU 4635的题解

    今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...

随机推荐

  1. Asycn/Await 异步编程初窥(二)

    经过总过4天的学习和实践,做完了 WinForm 下 .Net 4.5 的基本异步应用,实现了一个 Http 协议下载的测试程序,为以后使用 .Net 4.5 积累知识和经验.这个小程序完成这样几个作 ...

  2. ASP.NET MVC企业开发的基本环境

    ASP.NET MVC企业开发的基本环境[资源服务器概念] 学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang  茗洋  EasyUI1.3.4   ...

  3. js的onclick和jquery的bind事件执行先后顺序

    近期在项目中为每一个ajax触发按钮写正在加载的效果,用的是bootstarp 代码如下 $(function(){ $('.btn').bind('click',function(e){ var $ ...

  4. SSH的整合

    SSH的整合 struts2和hibernate的配置我这里就不多说了,先把两个有关的东西说下.一个是所有的包.struts2+hibernate3+spring2.5我包准备放上去给大家下载. ht ...

  5. 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 ...: ...

  6. VC 编程ANSI环境下读写Unicode文件

    没有注意到文件编码的不同会产生这么多的问题,在动手以前查询了很多资料,在本博客中收藏了不少先辈的成果,在这里一并表示致敬!       关于ANSI和Unicode编码的原理在这里也不说了,主要讲下如 ...

  7. Arduino 各种模块篇 震动模块 vibrator

    vibrator is a good thing. it has multi-funtionality . :) Now the  vibrator we choose is the one whic ...

  8. Yellow

    Yellow这首歌让我知道了yellow这个单词出了黄色的意思外,还有胆怯的,懦弱的意思~~~ 它是Coldplay 的歌曲,歌词很简单,但是有着莫名的忧伤感,值得一提的是这首歌的MV,一个长镜头给出 ...

  9. Web 请求响应原理(转)

    用Java实现Web服务器 减小字体 增大字体 摘要:WWW的工作基于客户机/服务器计算模型,由Web 浏览器(客户机)和Web服务器(服务器)构成,两者之间采用超文本传送协议(HTTP)进行通信,H ...

  10. Cocos2d-x 截图功能

    2.x-3.x版本                 //获取屏幕尺寸         CCSize size = CCDirector::sharedDirector()->getWinSize ...