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 ...
随机推荐
- “网易有钱”sketch使用分享
本文来自网易云社区 写在开头,关于ps与sketch之间的优劣网上已经有很多分享,大家有兴趣可以百度,其中对否我们在这里不予评价.在移动互联网时代每个app从几十到上百张页面,如果用ps绘制一个个页面 ...
- Android 9 适配怎么做? “QQ音乐”优化实录
WeTest 导读 2018年8月7日,Google对外发布最新 Android 9.0 正式版系统,并宣布系统版本Android P 被正式命名为代号“Pie”,最新系统已经正式推送包括谷歌Pixe ...
- Java应用基础微专业-工程篇
第1章-命令行 1.1 命令行基础 ls -a: list all files (including hidden files) .DS_Store: files detailed informati ...
- leetcode-单词探索
单词搜索 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单元格内的字母 ...
- 有个AI陪你一起写代码,是种怎样的体验?| 附ICLR论文
从前,任何程序的任何功能,都需要一行一行敲出来. 后来,程序猿要写的代码越来越多,世界上便有了各种各样的API,来减少大家的工作量.有些功能,可以让API来帮我们实现. 不过,人类写下的话,API并不 ...
- leetcode个人题解——#17 Letter Combinations of a Phone Number
思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值. class Solution { public: int len; ]={"a ...
- Python3 Tkinter-Scrollbar
1.创建 from tkinter import * root=Tk() Scrollbar(root).pack() root.mainloop() 2.设置silder的位置 from tkint ...
- Spring Boot - Filter实现简单的Http Basic认证
Copy自http://blog.csdn.net/sun_t89/article/details/51916834 @SpringBootApplicationpublic class Spring ...
- JavaScript初探系列之String的基本操作
1.字符串转换 字符串转换是最基础的要求和工作,你可以将任何类型的数据都转换为字符串,你可以用下面三种方法的任何一种: var myStr = num.toString(); // "19& ...
- Python 循环语句和运算符
while 循环 while 条件 : //条件为True时,执行while下带有缩进的语句 语句1 语句2 语句3 for循环 for循环可以用来遍历某一对象(遍历:通俗点说,就是把这个循环中的第一 ...