• <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>

            學習心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

            文字可能放在http://blog.csdn.net/superlong100,此處存放代碼

            常用鏈接

            留言簿(4)

            我參與的團隊

            搜索

            •  

            最新隨筆

            最新評論

            • 1.?re: Poj 1279
            • 對于一個凹多邊形用叉積計算面積 后能根據結果的正負來判斷給的點集的時針方向?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫的這個get_fail() 好像并是真正的get_fail,也是說fail指向的串并不是當前結點的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄]
            • 這個是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評論內容較長,點擊標題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發在這里很不錯..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評論排行榜

            #include <iostream>
            #include 
            <string.h>
            using namespace std;

            struct tree
            {
                tree 
            *next[26], *fail;
                
            int flag, len, ;
            };

            tree 
            *root, *p;
            tree arr[
            500001];
            int  indexx;
            char letter = 'a';

            void newn()
            {
                arr[indexx].fail 
            = NULL;
                arr[indexx].flag 
            = 0;
                arr[indexx].len 
            = -1;
                
            for(int i = 0; i < 26; i ++) arr[indexx].next[i] = 0;
            }

            void insert(char ch[], int w)
            {
                p 
            = root;
                
            int tmp, i = 0;
                
            while(ch[i])
                {
                    tmp 
            = ch[i] - letter;
                    
            if(p->next[tmp] == 0)
                    {
                        newn();
                        p
            ->next[tmp] = &arr[indexx ++];
                        p
            ->next[tmp]->len = p->len + 1;
                    }
                    p 
            = p->next[tmp];
                    i 
            ++;
                }
                
            if(!p->flag)
                    p
            ->flag = w;
            }

            tree 
            *que[500005];

            void get_fail()
            {
                p
            =root;
                p
            ->fail = root;
                
            int open = 0, close = -1, i;
                que[
            0= p;
                
            while(close < open)
                {
                    p 
            = que[++ close];
                    
            for(i = 0; i < 26; i ++)
                    {
                        
            if(p->next[i] == 0
                        {
                            
            if(p == root)    p->next[i] = root;
                            
            else            p->next[i] = p->fail->next[i];
                        }
                        
            else
                        {
                            
            if(p == root)    p->next[i]->fail = root;
                            
            else            p->next[i]->fail = p->fail->next[i];
                            que[
            ++open] = p->next[i];
                        }
                    }
                }
            }

            int ans[2][100005];
            int pos[100005];

            void query(char ch[])
            {
                p 
            = root;
                tree 
            *q;
                
            int t, i = 0;
                
            while(ch[i])
                {
                    t 
            = ch[i] - letter;
                    p 
            = p->next[t];
                    q 
            = p;
                    
            while(q != root && q->fail )
                    {
                        
            if(q->flag)
                        {
                            ans[
            0][q->flag] ++;
                            
            if(i - pos[q->flag] > q->len)
                            {
                                ans[
            1][q->flag] ++;
                                pos[q
            ->flag] = i;
                            }
                        }
                        q 
            = q->fail;
                    }
                    i 
            ++;
                }
            }

            int search(char ch[])
            {
                p 
            = root;
                
            int tmp, i = 0;
                
            while(ch[i])
                {
                    tmp 
            = ch[i] - letter;
                    p 
            = p->next[tmp];
                    i 
            ++;
                }
                
            return p->flag;
            }

            void init()
            {
                indexx 
            = 0;
                newn();
                root 
            = &arr[indexx ++];
                memset(ans, 
            0sizeof(ans));
                memset(pos, 
            -1sizeof(pos));
            }

            char str[100005];
            char dic[100005][7];
            int  typed[100005];

            int main()
            {
                
            int test = 0;
                
            while(scanf("%s", str) != EOF)
                {
                    
            int n, i;
                    init();
                    scanf(
            "%d"&n);
                    
            for(i = 1; i <= n; i ++)
                    {
                        scanf(
            "%d %s"&typed[i], dic[i]);
                        insert(dic[i], i);
                    }
                    get_fail();
                    query(str);
                    printf(
            "Case %d\n",++test);
                    
            for(i = 1; i <= n; i ++)
                    {
                        
            int id = search(dic[i]);
                        printf(
            "%d\n", ans[typed[i]][id]);
                    }
                    puts(
            "");
                }
            }

            posted on 2009-09-08 12:17 superlong 閱讀(463) 評論(0)  編輯 收藏 引用
            99久久国产亚洲高清观看2024 | 精品久久久久中文字幕一区| 色综合久久天天综合| 欧美日韩精品久久久久| 国内精品人妻无码久久久影院| 亚洲精品高清国产一久久| 久久午夜免费视频| 国产综合久久久久| 亚洲国产综合久久天堂| 青青草国产成人久久91网| 久久国产欧美日韩精品免费| 久久er国产精品免费观看2| 久久笫一福利免费导航| 久久国产热这里只有精品| 久久久久久人妻无码| 久久精品中文无码资源站| 久久亚洲AV永久无码精品| 91久久九九无码成人网站| 精品久久久久久成人AV| 久久久精品人妻一区二区三区蜜桃| 办公室久久精品| 国内精品久久久人妻中文字幕| 成人综合久久精品色婷婷| 色综合久久天天综线观看| 国产成人综合久久精品尤物| 久久91精品国产91久久麻豆| 精品久久久久久无码专区不卡 | 久久成人国产精品| 久久久久久国产a免费观看黄色大片| 久久国产乱子伦精品免费午夜| segui久久国产精品| 久久香蕉国产线看观看99| 99久久免费国产精精品| 久久久久久人妻无码| 国产精品久久久久aaaa| 四虎国产永久免费久久| 日本久久久久久中文字幕| 91秦先生久久久久久久| 久久精品一区二区三区中文字幕| 国产精品免费久久久久电影网| 国产免费久久久久久无码|