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

            換了個(gè)地址:http://www.cnblogs.com/vizhen/

             

            HDOJ 1671 Phone List

            題目傳送門

            簡(jiǎn)要分析字典樹(shù)問(wèn)題。但是要釋放內(nèi)存,否則會(huì)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 //建樹(shù)擴(kuò)展:當(dāng)有結(jié)尾的點(diǎn)出現(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 閱讀(327) 評(píng)論(0)  編輯 收藏 引用 所屬分類: ACM解題報(bào)告

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            coding是我的寂寞,我是誰(shuí)的寂寞

            隨筆分類(40)

            隨筆檔案(48)

            搜索

            積分與排名

            最新評(píng)論

            評(píng)論排行榜

            日本久久中文字幕| 精品多毛少妇人妻AV免费久久 | 国产成人无码久久久精品一| 亚洲综合熟女久久久30p| 国产成人久久精品一区二区三区| 99国产欧美精品久久久蜜芽| 国产激情久久久久影院| 久久久久久久97| 久久免费高清视频| 久久久久久久97| 久久久久噜噜噜亚洲熟女综合| 欧洲国产伦久久久久久久| 99久久精品国产毛片| 一日本道伊人久久综合影| 久久精品女人天堂AV麻| 久久精品不卡| 综合久久一区二区三区 | 日韩欧美亚洲综合久久影院d3| 久久强奷乱码老熟女网站| 国产精品久久久久影院嫩草| 精品久久久一二三区| 久久久久婷婷| 色综合久久中文色婷婷| 久久发布国产伦子伦精品| 国产偷久久久精品专区 | 久久精品视频一| 国产无套内射久久久国产| 久久99精品久久久久久| 久久A级毛片免费观看| 久久久久99精品成人片欧美| 亚洲国产精品高清久久久 | 久久婷婷综合中文字幕| 久久国产精品成人影院| 999久久久无码国产精品| 久久婷婷成人综合色综合| 亚洲AV日韩AV永久无码久久| 久久综合精品国产二区无码| 无码人妻精品一区二区三区久久| 精品久久久久久国产| 久久国产欧美日韩精品| 国产婷婷成人久久Av免费高清|