首页 > 其他 > 详细

poj2945:Find the Clones——题解

时间:2017-11-19 12:19:33      阅读:191      评论:0      收藏:0      [点我收藏+]

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

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

#include<cstdio>
#include<cstring>
using namespace std;
struct node{
    int ed;
    int son[4];
    void clear(){
    memset(son,0,sizeof(son));
    ed=0;
    }
}tree[500050];
inline int turn(char ch){
    if(ch==A)return 0;
    if(ch==C)return 1;
    if(ch==G)return 2;
    return 3;
}
char s[20050][25];
int t[20001];
int tot;
int n,m;
void insert(int k){
    int l=m;
    int now=1;
    for(int i=0;i<l;i++){
    if(tree[now].son[turn(s[k][i])]==0){
        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!=0)){
    for(int i=1;i<=500049;i++)tree[i].clear();
    tot=1;
    memset(t,0,sizeof(t));
    for(int i=1;i<=n;i++){
        char ch=0;int j=0;
        while(ch<A||ch>Z)ch=getchar();
        while(ch>=A&&ch<=Z){s[i][j]=ch;ch=getchar();j++;}
        insert(i);
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",t[i]);
    }
    }
    return 0;
}

 

poj2945:Find the Clones——题解

原文:http://www.cnblogs.com/luyouqi233/p/7859303.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!