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

            單鏈DNA

            換了個地址:http://www.cnblogs.com/vizhen/

             

            HDOJ 1671 Phone List

            題目傳送門

            簡要分析字典樹問題。但是要釋放內(nèi)存,否則會MLE.... = =!


            代碼
             1 #include <iostream>
             2 
             3 bool flag=false;//重復(fù)標(biāo)記
             4 const int MAXSIZE=10;
             5 struct Trie
             6 {
             7     int tail;//標(biāo)記結(jié)束
             8     int count;//標(biāo)記頻率
             9     Trie *next[MAXSIZE];
            10     Trie()
            11     {
            12         tail=0;
            13         count=1;
            14         for (int i=0;i<MAXSIZE;i++)
            15         {
            16             next[i]=NULL;
            17         }
            18     }
            19 };
            20 
            21 //建樹擴展:當(dāng)有結(jié)尾的點出現(xiàn)頻率大于1次表示有重復(fù)
            22 void InsertWorldEx(Trie* &root,char *world)
            23 {
            24     Trie *location=root;
            25     int i=0,branch=0,len;
            26 
            27     len=strlen(world);
            28     while (world[i])
            29     {
            30         branch=world[i]-'0';
            31         if(location->next[branch]==NULL)
            32              location->next[branch]=new Trie;
            33         else
            34         {
            35             location->next[branch]->count++;
            36         }
            37         
            38         if(i==len-1)  location->next[branch]->tail=1;
            39         
            40         //標(biāo)記已經(jīng)有前綴重復(fù)
            41         if(location->next[branch]->tail==1&&location->next[branch]->count>1)
            42             flag=true;
            43         
            44         i++;
            45         location=location->next[branch];
            46     }      
            47 }
            48 int del(Trie* &root)
            49 {
            50     int i;
            51     if(root==NULL)
            52         return 0;
            53     for (i=0;i<MAXSIZE;i++)
            54     {
            55         if(root->next[i]!=NULL)
            56             del(root->next[i]);
            57     }
            58     free(root);
            59     return 0;
            60 }
            61 
            62 int main()
            63 {
            64     int t;
            65     scanf("%d",&t);
            66     while(t--)
            67     {
            68         int num;
            69         char phone[20];
            70         Trie *root=new Trie;
            71         flag=false;
            72 
            73         scanf("%d",&num);
            74         for (int i=0;i<num;i++)
            75         {
            76             scanf("%s",phone);
            77             if(flag==false) InsertWorldEx(root,phone);
            78         }
            79 
            80         if(flag) printf("NO\n");
            81         else printf("YES\n");
            82         del(root);
            83     }
            84     return 0;
            85 }
            86 

            相似題目HDOJ 1305 http://acm.hdu.edu.cn/showproblem.php?pid=1305


            posted on 2010-10-05 22:51 Geek.tan 閱讀(335) 評論(0)  編輯 收藏 引用 所屬分類: ACM解題報告

            導(dǎo)航

            統(tǒng)計

            公告

            coding是我的寂寞,我是誰的寂寞

            隨筆分類(40)

            隨筆檔案(48)

            搜索

            積分與排名

            最新評論

            評論排行榜

            国内精品久久久久久久久电影网| 久久久久久亚洲精品不卡| 久久青青草原国产精品免费 | 精品久久久久久99人妻| 无码人妻少妇久久中文字幕| 亚洲精品美女久久久久99| 国产高清美女一级a毛片久久w| 久久久久亚洲AV无码观看| 久久精品夜色噜噜亚洲A∨| 亚洲中文字幕无码久久综合网| 久久夜色精品国产亚洲| 久久久久人妻精品一区| 久久精品极品盛宴观看| 精品国产乱码久久久久久浪潮 | 久久99精品国产99久久6| 无码专区久久综合久中文字幕| 亚洲综合精品香蕉久久网97| 精品999久久久久久中文字幕| 久久青青草原精品国产| 免费精品国产日韩热久久| 999久久久国产精品| 国产成人综合久久综合| 久久精品国产精品青草| 色婷婷综合久久久中文字幕| av无码久久久久不卡免费网站| 久久人人爽爽爽人久久久| 精品久久亚洲中文无码| 久久午夜综合久久| 亚洲国产综合久久天堂| 久久久国产精华液| 伊人热热久久原色播放www| 欧美午夜A∨大片久久| 人人狠狠综合88综合久久| 理论片午午伦夜理片久久 | 国产成人精品久久一区二区三区| 久久夜色精品国产网站| 无码人妻精品一区二区三区久久 | 久久久精品午夜免费不卡| 亚洲一区中文字幕久久| 久久青青草原亚洲av无码app| 国产三级久久久精品麻豆三级|