zoukankan      html  css  js  c++  java
  • HDU

    很久之前刷的专题,今天准备学ac自动机打算复习一下,突然发现博客里没有= = 

    所以把模板拉过来

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<iomanip>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define pi acos(-1)
    #define ll long long
    #define mod 1000000007
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #define MIN(a,b) a<b ? a:b
    
    using namespace std;
    
    const double g=10.0,eps=1e-9;
    const int N=400000+10,maxn=1000+10,inf=1000000000;
    
    int cnt[N],tot;
    int Next[N][30];
    int Newnode()
    {
        cnt[tot]=0;
        memset(Next[tot],-1,sizeof Next[tot]);
        return tot++;
    }
    int main()
    {
       /* ios::sync_with_stdio(false);
        cin.tie(0);*/
        char s[N];
        int root;
        tot=0;
        root=Newnode();
        while(gets(s)&&strlen(s)){
            int now=root;
            for(int i=0;s[i];i++)
            {
                if(Next[now][s[i]-'a']==-1)
                {
                    Next[now][s[i]-'a']=Newnode();
                }
                now=Next[now][s[i]-'a'];
                ++cnt[now];
            }
        }
        while(scanf("%s",&s)!=EOF){
            int now=root;
            for(int i=0;s[i];i++)
            {
                now=Next[now][s[i]-'a'];
                if(now==-1)break;
            }
            printf("%d
    ",cnt[now]);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    OpenCV(一)
    python中的协程(一)
    python中的协程(三)
    ubuntu18.04 与 python
    js高级
    Django学习笔记5
    Django学习笔记6
    MongoDB 4.03简易使用教程
    python中的协程(二)
    js 词法分析
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/7543408.html
Copyright © 2011-2022 走看看