• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            syhd142  
            日歷
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567
            統計
            • 隨筆 - 23
            • 文章 - 122
            • 評論 - 31
            • 引用 - 0

            導航

            常用鏈接

            留言簿(2)

            隨筆檔案(23)

            文章分類(270)

            文章檔案(122)

            我的豆瓣

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

             
            模板題
            #include <stdio.h>
            #include 
            <string.h>
            #include 
            <math.h>
            #include 
            <queue>

            #define KIND 26
            #define N 1005
            #define M 2000005

            struct node
            {
                node 
            *fail;
                node 
            *next[KIND];
                
            int id;
                node ()
                    {
                        fail 
            = NULL;
                        id 
            = 0;
                        memset(next, 
            0sizeof(next));
                    }
            };

            char ch[M], key[N][55];
            int count[N];

            void insert(node *&root, char *ch, int num)
            {
                node 
            *= root;
                
            int i = 0, t;
                
            while(ch[i])
                {
                    t 
            = ch[i] - 'A';
                    
            if(!p->next[t]) p->next[t] = new node();
                    p 
            = p->next[t];
                    i
            ++;
                }
                p
            ->id = num;
            }

            void AC(node *&root)
            {
                std::queue
            <node *> q;
                q.push(root);
                
            while(!q.empty())
                {
                    node 
            *= NULL;
                    node 
            *= q.front();
                    q.pop();
                    
            for(int i = 0; i < KIND; i++)
                    {
                        
            if(t->next[i])
                        {
                            p 
            = t->fail;
                            
            while(p)
                            {
                                
            if(p->next[i])
                                {
                                    t
            ->next[i]->fail = p->next[i];
                                    
            break;
                                }
                                p 
            = p->fail;
                            }
                            
            if(!p) t->next[i]->fail = root;
                            q.push(t
            ->next[i]);
                       }
                    }
                }
            }

            void query(node *&root, char *ch)
            {
                
            int i = 0, t;
                node 
            *= root, *tmp;
                
            while(ch[i])
                {
                    
            if(ch[i] > 'Z' || ch[i] < 'A')
                    {
                        p 
            = root;
                        i
            ++;
                        
            continue;
                    }
                    t 
            = ch[i] - 'A';
                    
            while(!p->next[t] && p != root) p = p->fail;
                    p 
            = p->next[t];
                    
            if(!p) p = root;
                    tmp 
            = p;
                    
            while(tmp != root)
                    {
                        count[tmp
            ->id]++;
                        tmp 
            = tmp->fail;
                    }
                    i
            ++;
                }
            }

            int main()
            {
                
            int n;
                
            while(~scanf("%d"&n))
                {
                    node 
            *root = new node();
                    memset(count, 
            0sizeof(count));
                    
            for(int i = 1; i <= n; i++)
                    {
                        scanf(
            "%s", key[i]);
                        insert(root, key[i], i);
                    }
                    AC(root);
                    scanf(
            "%s", ch);
                    query(root, ch);
                    
            for(int i = 1; i <= n; i++)
                    {
                        
            if(count[i])
                        {
                            printf(
            "%s: %d\n", key[i], count[i]);
                        }
                    }
                }
                
            return 0;
            }
            posted on 2011-01-10 15:58 Fucker 閱讀(492) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC字符串
             
            Copyright © Fucker Powered by: 博客園 模板提供:滬江博客
            国产69精品久久久久9999| 久久亚洲私人国产精品| 久久精品无码一区二区三区日韩| 国产三级久久久精品麻豆三级| 69SEX久久精品国产麻豆| 91超碰碰碰碰久久久久久综合| 久久综合色老色| 美女写真久久影院| 久久99九九国产免费看小说| 精品久久久久香蕉网| 思思久久99热只有频精品66| 精品久久久久香蕉网| 少妇熟女久久综合网色欲| 国产精品99久久精品爆乳| 亚洲精品tv久久久久久久久| 久久综合狠狠综合久久97色| 久久国产精品久久国产精品| 久久婷婷国产剧情内射白浆| 国产免费久久精品99久久| 国内精品久久人妻互换| 久久久久久精品无码人妻| 国产A级毛片久久久精品毛片| 久久精品中文无码资源站| 久久国产亚洲精品| 三级韩国一区久久二区综合 | 久久精品国产99国产精品| 色狠狠久久AV五月综合| 久久乐国产精品亚洲综合| 久久亚洲AV无码西西人体| 精品国产青草久久久久福利| 99精品久久精品| 九九久久99综合一区二区| 久久精品国产精品亚洲毛片| 久久久久国产精品嫩草影院| 亚洲七七久久精品中文国产| 久久久久无码国产精品不卡| 久久www免费人成看国产片| 久久国产成人午夜AV影院| 精品久久久久久久中文字幕| 久久AⅤ人妻少妇嫩草影院| 国产成人精品久久亚洲高清不卡|