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. itop4412开发板添加开机启动程序

    1. 先编写代码,以helloworld.c为例子 #include<stdio.h> #include<unistd.h> //这个文件是什么 main() { ; ) { ...

  2. redis 学习笔记二

    redis启动: 直接 redis-server.exe 启动服务,是按照redis默认配置启动的,如果想按照自己的配置文件启动,要加上 redis-server.exe  redis.windows ...

  3. RSA加密通信小结(二)-新版本APP与后台通信交互内容修改方案

    注1:本次修改分为两步,首先是内容相关的修改,待其完成之后,再进行加密通信项(粗体字备注)修改. 1.新的提交后台的格式包括:data,token(预留字段,暂时后台不校验),userId(已有的不删 ...

  4. MySQL日期比较

    假如有个表product有个字段add_time,它的数据类型为datetime,有人可能会这样写sql: select * from product where add_time = '2013-0 ...

  5. Qt-QML-Loader初步接触

    先说说为什么用到了QML的Loader,这里我就要先扯点别的,那就是QML自带的ColorDialog,QML的机制 是优先调用系统提供的ColorDialog,如果系统的ColorDialog的不可 ...

  6. 180605-Linux下Crontab实现定时任务

    Linux下Crontab实现定时任务 基于Hexo搭建的个人博客,是一种静态博客页面,每次新增博文或者修改,都需要重新的编译并发布到Github,这样操作就有点蛋疼了,一个想法就自然而然的来了,能不 ...

  7. Appium(Python)测试混血App

    Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app兼具Native App良好用户交互体验的优势和Web App跨平台开发的优势 HybridApp ...

  8. 孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1

    孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1 (完整学习过程屏幕记录视频地址在文末) 要模拟进行浏览器操作,只用requests是不行的,因此今天了解到有专门的解决方案 ...

  9. python 打包

    一.下载 pip install Pyinstaller 二.使用Pyinstaller 1.使用下载安装的方式安装的Pyinstaller打包方式 将需要打包的文件放在解压得到的Pyinstalle ...

  10. Cassandra 类型转换限制

    原文地址:http://stackoverflow.com/questions/31880381/cassandra-alter-column-type-which-types-are-compati ...