建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<cctype>
  7. #include<cstdlib>
  8. #include<vector>
  9. #include<queue>
  10. #include<map>
  11. #include<set>
  12. #define ll long long
  13. #define R register int
  14. using namespace std;
  15. namespace Fread {
  16. static char B[<<],*S=B,*D=B;
  17. #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
  18. inline int g() {
  19. R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
  20. do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
  21. } inline bool isempty(const char& ch) {return ch<=||ch>=;}
  22. inline void gs(char* s) {register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar()));}
  23. }using Fread::g; using Fread::gs;
  24. const int N=;
  25. int t[N][],cnt[N],tot,ans[N],n,m;
  26. inline int calc(const char& ch) {
  27. if(ch=='A') return ;
  28. else if(ch=='C') return ;
  29. else if(ch=='G') return ;
  30. return ;
  31. }
  32. inline void ins(char* s) { R len=strlen(s),now=;
  33. for(R i=;i<len;++i) {
  34. R ch=calc(s[i]);
  35. if(!t[now][ch]) t[now][ch]=++tot;
  36. now=t[now][ch];
  37. } --ans[cnt[now]],++ans[++cnt[now]];
  38. }
  39. signed main() {
  40. #ifdef JACK
  41. freopen("NOIPAK++.in","r",stdin);
  42. #endif
  43. while(~scanf("%d%d",&n,&m)) {
  44. memset(ans,,sizeof(ans)),memset(t,,sizeof(t)),
  45. memset(cnt,,sizeof(cnt)),tot=;
  46. for(R i=;i<=n;++i) {register char s[]; scanf("%s",s),ins(s);}
  47. for(R i=;i<=n;++i) printf("%d\n",ans[i]);
  48. }
  49. }

2019.06.13

POJ2945 Find the Clones trie树的更多相关文章

  1. POJ2945(Find the Clones)--字典树,map

    题意:给你n个规定长度的单词,问你其中出现了1次的单词,出现两次的单词...出现n次单词分别有多少个. 当然这题map也能过,但是这里介绍字典树的做法. 首相对于n个单词存入树中,当然建树过程中遇到一 ...

  2. POJ 2945 trie树

    Find the Clones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7704 Accepted: 2879 Descr ...

  3. 基于trie树做一个ac自动机

    基于trie树做一个ac自动机 #!/usr/bin/python # -*- coding: utf-8 -*- class Node: def __init__(self): self.value ...

  4. 基于trie树的具有联想功能的文本编辑器

    之前的软件设计与开发实践课程中,自己构思的大作业题目.做的具有核心功能,但是还欠缺边边角角的小功能和持久化数据结构,先放出来,有机会一点点改.github:https://github.com/chu ...

  5. hihocoder-1014 Trie树

    hihocoder 1014 : Trie树 link: https://hihocoder.com/problemset/problem/1014 题意: 实现Trie树,实现对单词的快速统计. # ...

  6. 洛谷P2412 查单词 [trie树 RMQ]

    题目背景 滚粗了的HansBug在收拾旧英语书,然而他发现了什么奇妙的东西. 题目描述 udp2.T3如果遇到相同的字符串,输出后面的 蒟蒻HansBug在一本英语书里面找到了一个单词表,包含N个单词 ...

  7. 通过trie树实现单词自动补全

    /** * 实现单词补全功能 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #incl ...

  8. #1014 Trie树

    本题主要是求构造一棵Trie树,即词典树用于统计单词. C#代码如下: using System; using System.Collections.Generic; using System.Lin ...

  9. Trie树-字典查找

    描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进. 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题: ...

随机推荐

  1. 通过rtmpdump推送海康视频流到red5服务器

    现在主流的网络摄像机都支持标准H264视频格式,例如 海康网络摄像机, 通过海康提供的网络SDK可以获取到视频码流.我测试的这款相机,视频编码采用的是H264,音频编码采用的是G711a. 这里,我仅 ...

  2. hdu 3998 Sequence

    There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X as x[i1], ...

  3. UNITY_MATRIX_IT_MV[Matrix]

    http://blog.csdn.net/cubesky/article/details/38682975 前面发了一篇关于unity Matrix的文章. http://blog.csdn.NET/ ...

  4. [转]HTTP Header 详解

    HTTP Header 详解 HTTP(HyperTextTransferProtocol) 即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模 型,浏览器或其他客户端发出请求 ...

  5. BZOJ2212:[POI2011]Tree Rotation

    浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...

  6. binlog配置和使用

    binlog启用和禁用在/etc/my.cnf文件中添加log-bin=mysql-bin来启用binlog,mysql-bin为日志文件名前缀.如果用户有super权限,可通过set sql_log ...

  7. Java常见设计模式之代理模式

    指由一个代理主题来操作真实主题,真实主题执行具体的业务操作,而代理主题负责其它相关业务的处理.比如生活中的通过代理访问网络,客户通过网络代理连接网络(具体业务),由代理服务器完成用户权限和访问限制等与 ...

  8. 使用union来遍历结构体中的成员

    前几天和实验室的同学讨论问题的时候发现他使用的一段数据校验的代码自己以前没有接触过,今天有空就把它整理了一下. #include <stdio.h> #include <stdlib ...

  9. File 类 操作实例

    File 操作 <介绍> 尽管java.io定义的大多数类是实行流式操作的,File类不是.它直接处理文件和文件系统.也就是说,File类没有指定信息怎样从文件读取或向文件存储:它描述了文 ...

  10. Spring 3.x 企业引用开发实战(陈雄华/林开雄)

    目录 ... 第一章:Spring概述 IoC:BeanFactory.Context.El(SpringEL表达式) AOP:允许JVM虚拟机启动时使用代理类在运行时期修改指定类的字节码,改变一个类 ...