标签:ons ima 多少 gif nbsp 更新 div string names
建一颗$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\n",ans[i]); } }
2019.06.13
标签:ons ima 多少 gif nbsp 更新 div string names
原文地址:https://www.cnblogs.com/Jackpei/p/11013610.html