• <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 <stdio.h>

            struct tree
            {
                tree 
            *fail, *next[2];
                
            int flag, visit;
            };

            tree arr[
            30005];
            int  indexx;
            tree 
            *root, *p;

            void newn()
            {
                arr[indexx].fail 
            = NULL;
                arr[indexx].flag 
            = 0;
                arr[indexx].visit 
            = 0;
                
            for(int i = 0; i < 2; i ++) arr[indexx].next[i] = 0;
            }

            void init()
            {
                indexx 
            = 0;
                newn();
                root 
            = &arr[indexx ++];
            }

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

            tree 
            *que[30005];

            bool check(tree *q)
            {
                
            while(q != root)
                {
                    
            if(q->flag) return true;
                    q 
            = q->fail;
                }
                
            return false;
            }

            void get_fail()
            {
                
            int close = -1, open = 0;
                p 
            = root; p->fail = root;
                que[
            0= p;
                
            while(close < open)
                {
                    p 
            = que[++close];
                    
            for(int i = 0; i < 2; i ++)
                    {
                        
            int danger;
                        
            if(danger = check(p)) p->flag = 1;
                        
            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  n;
            char str[30005];
            bool ok;

            void solve(tree *q)
            {
                
            for(int i = 0; i < 2; i ++)
                {
                    
            if(q->next[i]->visit)
                    {
                        ok 
            = true
                        
            return;
                    }
                    
            if(q->next[i]->flag) continue;
                    q
            ->next[i]->flag = 1;
                    q
            ->next[i]->visit = 1;
                    solve(q
            ->next[i]);
                    
            if(ok) return;
                    q
            ->next[i]->visit = 0;
                }
            }

            int main()
            {
                
            while(scanf("%d",&n) != EOF)
                {
                    init();
                    
            for(int i = 0; i < n; i ++
                    {
                        scanf(
            "%s", str);
                        insert(str);
                    }
                    get_fail();
                    root
            ->visit = true;
                    ok 
            = false;
                    solve(root);
                    
            if(ok)     puts("TAK");
                    
            else    puts("NIE");
                }
                
            return 0;
            }

            posted on 2009-09-11 14:07 superlong 閱讀(194) 評論(0)  編輯 收藏 引用
            亚洲精品美女久久久久99小说| 久久午夜伦鲁片免费无码| 精品国产综合区久久久久久| 久久免费大片| 99久久精品国内| 亚洲国产精品一区二区久久hs | 久久AⅤ人妻少妇嫩草影院| 亚洲精品国产综合久久一线| 精品国产一区二区三区久久| 伊人色综合久久天天网| 91精品国产综合久久精品| 欧美国产成人久久精品| 99久久精品免费国产大片| 精品伊人久久大线蕉色首页| 久久无码人妻精品一区二区三区 | 国产精品久久久久久福利漫画 | 亚洲国产天堂久久久久久| 伊人色综合久久| 国产精品久久久久久吹潮| 亚洲国产精品无码久久久不卡 | 亚洲国产成人久久精品影视| 久久无码人妻一区二区三区午夜| 一本色综合久久| 色婷婷久久综合中文久久一本| 国产综合成人久久大片91| 国产免费久久精品丫丫| 亚洲国产精品久久久久网站| 久久精品嫩草影院| 久久九九亚洲精品| 91久久福利国产成人精品| 中文字幕久久欲求不满| 国产精品99久久久久久宅男| 精品综合久久久久久97超人| 亚洲嫩草影院久久精品| 精品久久久久久国产三级| 久久www免费人成精品香蕉| 久久精品国产亚洲AV不卡| 久久这里有精品视频| 亚洲精品国精品久久99热| 亚洲av伊人久久综合密臀性色| 国内精品久久久久久久久电影网 |