http://poj.org/problem?id=2945

还是trie树……对于结束标记累加并且开个数组记录一下即可。

#include<cstdio>
#include<cstring>
using namespace std;
struct node{
int ed;
int son[];
void clear(){
memset(son,,sizeof(son));
ed=;
}
}tree[];
inline int turn(char ch){
if(ch=='A')return ;
if(ch=='C')return ;
if(ch=='G')return ;
return ;
}
char s[][];
int t[];
int tot;
int n,m;
void insert(int k){
int l=m;
int now=;
for(int i=;i<l;i++){
if(tree[now].son[turn(s[k][i])]==){
tot++;
tree[now].son[turn(s[k][i])]=tot;
}
now=tree[now].son[turn(s[k][i])];
}
t[tree[now].ed]--;
tree[now].ed++;
t[tree[now].ed]++;
return;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF&&(m!=n&&n!=)){
for(int i=;i<=;i++)tree[i].clear();
tot=;
memset(t,,sizeof(t));
for(int i=;i<=n;i++){
char ch=;int j=;
while(ch<'A'||ch>'Z')ch=getchar();
while(ch>='A'&&ch<='Z'){s[i][j]=ch;ch=getchar();j++;}
insert(i);
}
for(int i=;i<=n;i++){
printf("%d\n",t[i]);
}
}
return ;
}

POJ2945:Find the Clones——题解的更多相关文章

  1. poj2945 Find the Clones

    Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8490   Accepted: 3210 D ...

  2. POJ2945 Find the Clones trie树

    建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...

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

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

  4. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  5. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  6. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  7. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  8. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  9. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

随机推荐

  1. 用Scanner读文本文件内容

    import java.io.File; import java.util.Scanner; class Demo { public static void main(String[] args) t ...

  2. 问题:Visual Studio 2017 无法推送到github:The requested URL returned error: 403

    问题: Visual Studio 2017 无法推送到github:The requested URL returned error: 403 原因分析: Visual Studio 2017记录的 ...

  3. 引领技术变革,腾讯云、腾讯WeTest和英特尔,合作布局云游戏

    WeTest 导读 ChinaJoy作为中国泛娱乐产业年度风向标,受到全球业界的高度关注.在本届ChinaJoy上,腾讯云.腾讯WeTest和英特尔,合作为游戏玩家.游戏开发者等业界人士联合展出了云游 ...

  4. yield学习

    如果要控制内存占用,最好不要用list来保存中间结果,而是通过iterable对象(range, xrange, generator等)来迭代.   yield 使函数变为generator,返回对象 ...

  5. 「日常训练」COMMON 约数研究(HYSBZ-1968)

    题意与分析 感谢https://www.cnblogs.com/Leohh/p/7512960.html的题解.这题话说原来不在我的训练范围,正好有个同学问我,我就拿来做做.数学果然不是我擅长的啊,这 ...

  6. MySQL连接本地数据库时报1045错误的解决方法

     navicat for MySQL 连接本地数据库出现1045错误 如下图:  说明连接mysql时数据库密码错误,需要修改密码后才可解决问题: 解决步骤如下: .首先打开命令行:开始->运行 ...

  7. 165. Merge Two Sorted Lists【LintCode by java】

    Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new so ...

  8. Ducci序列 (Ducci Sequence,ACM/ICPC Seoul 2009,UVa1594)

    题目描述: 题目思路: 直接模拟 #include<stdio.h> #include<string.h> #define maxn 105 int less(const ch ...

  9. 【转载】appium 操作汇总

    '''.appium api第二弹 锋利的python,这是初稿,2015/1/5 如有错误的地方,请同学们进行留言,我会及时予以修改,尽量整合一份ok的api 作者:Mads Spiral QQ:7 ...

  10. 详解Jedis连接池报错处理

    在使用Jedis连接池模式下,比较常见的报错如下: redis.clients.jedis.exceptions.JedisConnectionException:Could not get a re ...