• <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久久精品免费观看国产| 久久人人超碰精品CAOPOREN | 国产综合久久久久| 久久久黄片| a高清免费毛片久久| 久久久久人妻精品一区三寸蜜桃| 一本色道久久综合亚洲精品| 国产精品无码久久综合网| 久久天天躁狠狠躁夜夜avapp| 国产成人久久久精品二区三区| 久久精品日日躁夜夜躁欧美| 亚洲午夜精品久久久久久人妖| 亚洲国产另类久久久精品| 久久久青草青青国产亚洲免观| 国产精品久久永久免费| 国产A级毛片久久久精品毛片| 久久综合久久伊人| 国产成人无码精品久久久久免费| 777米奇久久最新地址| 国产成人精品综合久久久久| 性做久久久久久久久久久| 久久久久香蕉视频| 久久精品9988| 久久国产精品久久| 国产欧美一区二区久久| 久久精品人人做人人爽电影蜜月| 久久久久亚洲av综合波多野结衣| 亚洲国产成人久久笫一页| 久久伊人亚洲AV无码网站| 久久精品亚洲精品国产欧美| 久久亚洲天堂| 狠狠色丁香久久婷婷综合蜜芽五月| 久久久精品人妻无码专区不卡| a级毛片无码兔费真人久久| 国内精品久久久久久久影视麻豆| 亚洲国产精品婷婷久久| 久久精品国产精品亚洲下载|