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
  • 相关阅读:
    [leetcode] Valid Sudoku
    [leetcode] Count and Say
    [leetcode] Decode Ways
    [leetcode] Sqrt(x)
    [leetcode] Best Time to Buy and Sell Stock II
    7-27 兔子繁衍问题
    7-26 最大公约数和最小公倍数
    7-25 求奇数和
    7-24 猜数字游戏
    7-23 分段计算居民水费
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/7543408.html
Copyright © 2011-2022 走看看