POJ2945:Find the Clones——题解
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——题解的更多相关文章
- poj2945 Find the Clones
Find the Clones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8490 Accepted: 3210 D ...
- POJ2945 Find the Clones trie树
建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...
- POJ2945(Find the Clones)--字典树,map
题意:给你n个规定长度的单词,问你其中出现了1次的单词,出现两次的单词...出现n次单词分别有多少个. 当然这题map也能过,但是这里介绍字典树的做法. 首相对于n个单词存入树中,当然建树过程中遇到一 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- Redis系列一 Redis安装
Redis系列一 Redis安装 1.安装所使用的操作系统为Ubuntu16.04 Redis版本为3.2.9 软件一般下载存放目录为/opt,以下命令操作目录均为/opt root@ubunt ...
- Oracle TDE的学习
TDE的开启和关闭 设置wallet目录,在参数文件sqlnet.ora中,按照下面的格式加入信息 # Oracle Advanced Security Transparent Data Encryp ...
- 「Python」matplotlib备忘录
总结了一下网上现有的资源,得到了一些东西.随手做个备忘. 更多设置见:https://matplotlib.org/users/customizing.html. 导入 import matplotl ...
- OSG-简单模型控制
本文转至http://www.cnblogs.com/shapherd/archive/2010/08/10/osg.html 作者写的比较好,再次收藏,希望更多的人可以看到这个文章 互联网是是一个相 ...
- Cannot assign requested address (connect failed)
压测时,应用服务器报错:Cannot assign requested address (connect failed) 经检查,由于应用服务器,频繁发起http请求,由于每次连接都在很短的时间内结束 ...
- tensorflow学习笔记(3)前置数学知识
tensorflow学习笔记(3)前置数学知识 首先是神经元的模型 接下来是激励函数 神经网络的复杂度计算 层数:隐藏层+输出层 总参数=总的w+b 下图为2层 如下图 w为3*4+4个 b为4* ...
- Python高级编程-多进程
要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...
- zookeeper启动配置
zookeeper安装和配置详解 转载 2014年04月16日 14:36:31 16812 摘自:http://www.ibm.com/developerworks/cn/opensource/os ...
- iOS开发UIColor,CGColor,CIColor三者的区别和联系
最近看了看CoreGraphics的东西,看到关于CGColor的东西,于是就想着顺便看看UIColor,CIColor,弄清楚它们之间的区别和联系.下面我们分别看看它们三个的概念: 一.UIColo ...
- Crash使用参考
整理自man 8 crash 1.简介 Crash工具可以用来分析一个正在运行的内核,也可以用来分析一个内核的crash dump文件,这里说的是内核代码异常产生的crash dump文件,不是应用层 ...