zoukankan      html  css  js  c++  java
  • POJ2945 Find the Clones trie树

    建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新。

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<cctype>
    #include<cstdlib>
    #include<vector>
    #include<queue>
    #include<map>
    #include<set>
    #define ll long long
    #define R register int
    using namespace std;
    namespace Fread {
        static char B[1<<15],*S=B,*D=B;
        #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
        inline int g() {
            R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
            do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
        } inline bool isempty(const char& ch) {return ch<=36||ch>=127;}
        inline void gs(char* s) {register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar()));}
    }using Fread::g; using Fread::gs;
    const int N=400010;
    int t[N][4],cnt[N],tot,ans[N],n,m;
    inline int calc(const char& ch) {
        if(ch=='A') return 0;
        else if(ch=='C') return 1;
        else if(ch=='G') return 2;
        return 3;
    }
    inline void ins(char* s) { R len=strlen(s),now=0;
        for(R i=0;i<len;++i) {
            R ch=calc(s[i]);
            if(!t[now][ch]) t[now][ch]=++tot;
            now=t[now][ch];
        } --ans[cnt[now]],++ans[++cnt[now]];
    }
    signed main() {
    #ifdef JACK
        freopen("NOIPAK++.in","r",stdin);
    #endif
        while(~scanf("%d%d",&n,&m)) {
            memset(ans,0,sizeof(ans)),memset(t,0,sizeof(t)),
            memset(cnt,0,sizeof(cnt)),tot=0;
            for(R i=1;i<=n;++i) {register char s[30]; scanf("%s",s),ins(s);} 
            for(R i=1;i<=n;++i) printf("%d
    ",ans[i]);
        }
    }

    2019.06.13

  • 相关阅读:
    UE 不生成.bak文件
    DOTWeen 使用
    unity admob
    UGUI 判断元素进入舞台
    unity 解决ScrollRect嵌套滚动问题
    oc字符串与c字符串转换和拷贝
    Object-c中的单例
    JAVA比较两个List集合的方法
    CentOS 7 配置静态IP
    CentOS7安装Jdk1.8
  • 原文地址:https://www.cnblogs.com/Jackpei/p/11013610.html
Copyright © 2011-2022 走看看