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

            hdu1251_統(tǒng)計(jì)難題

            Posted on 2010-12-07 16:34 李東亮 閱讀(2204) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): acm

            HDU 1251 統(tǒng)計(jì)難題

            要看論文準(zhǔn)備畢業(yè)設(shè)計(jì)了,好幾周都沒(méi)有搞ACM了,今天實(shí)在手癢了,就去hdu上溜達(dá)了一圈,挑幾個(gè)題做,于是乎就看到了這個(gè)題,典型的字典樹(shù)。

            題目要求輸出以某個(gè)字符串為前綴的word的數(shù)目,建立字典樹(shù)之后就是個(gè)簡(jiǎn)單的查詢了,為了性能采用了靜態(tài)字典樹(shù),由于不知道會(huì)有多少個(gè)單詞就猜了下感覺(jué)10w應(yīng)該夠了吧,提交上去access violation,明顯的越界訪問(wèn),修改為20W一樣出錯(cuò),后來(lái)火了,直接開(kāi)到50w過(guò)了,測(cè)試數(shù)據(jù)相當(dāng)狠呀。

            不多說(shuō)了,參考代碼如下。

            #include <stdio.h>
            #include 
            <stdlib.h>
            struct node
            {
                
            int cnt;
                
            int childs[26];
            };
            int avail = 1;
            int cur = 0;
            struct node tree[500000];
            char buf[15];
            int main(void)
            {
                
            int i;
                
            int root;
                
            int index;
                
            int flag;
                
            /*freopen("in.txt", "r", stdin);*/
                
            while (fgets(buf, 15, stdin) != NULL && buf[0!= '\n'
                {
                    i 
            = 0;
                    root 
            = 0;
                    
            while (buf[i] != '\n')
                    {
                        index 
            = buf[i]-'a';
                        
            if (tree[root].childs[index] == 0)
                        {
                            tree[root].childs[index] 
            = avail++;
                        }
                        
            ++tree[tree[root].childs[index]].cnt;
                        root 
            = tree[root].childs[index];
                        
            ++i;
                    }
                }

                
            while (fgets(buf, 15, stdin) != NULL && buf[0!= '\n'
                {
                    i 
            = 0;
                    root 
            = 0;
                    flag 
            = 1;
                    
            while (buf[i] != '\n')
                    {
                        index 
            = buf[i] - 'a';
                        
            if (tree[root].childs[index] == 0)
                        {
                            flag 
            = 0;
                            
            break;
                        }
                        root 
            = tree[root].childs[index];
                        
            ++i;
                    }
                    printf(
            "%d\n", flag == 1 ? tree[root].cnt : 0);
                }
                
            return 0;
            }


            Feedback

            # re: hdu1251_統(tǒng)計(jì)難題[未登錄](méi)  回復(fù)  更多評(píng)論   

            2010-12-07 17:20 by megax
            這內(nèi)存占的。。。。。雖然你解決了,似乎實(shí)用性不是太大。

            posts - 12, comments - 1, trackbacks - 0, articles - 1

            Copyright © 李東亮

            久久婷婷激情综合色综合俺也去 | 久久99精品国产麻豆蜜芽| 久久国产欧美日韩精品| 久久香蕉一级毛片| 久久精品国产福利国产琪琪| 亚洲精品久久久www| 精品熟女少妇a∨免费久久| 精品久久久久中文字| 久久久久亚洲av无码专区导航| 91精品国产91久久| 久久精品国产亚洲AV久| 国产精品欧美亚洲韩国日本久久| 777午夜精品久久av蜜臀| 久久久久亚洲精品男人的天堂| 亚洲国产精品成人久久| 久久这里有精品视频| 国内精品久久久久影院免费| 国产69精品久久久久9999APGF| 久久久久99精品成人片牛牛影视| 国产日产久久高清欧美一区| 一本久道久久综合狠狠爱| 亚洲伊人久久成综合人影院| 999久久久国产精品| 日本三级久久网| 91精品无码久久久久久五月天| 久久久久国产精品熟女影院| 国产偷久久久精品专区| 久久亚洲日韩看片无码| 亚洲成av人片不卡无码久久| 久久精品三级视频| 久久久中文字幕日本| 久久精品国产清自在天天线| 国产91久久综合| 99久久伊人精品综合观看| 一级做a爰片久久毛片人呢| 91精品国产91久久久久久蜜臀| 久久99国内精品自在现线| 99re久久精品国产首页2020| 91精品国产高清久久久久久io| 久久亚洲私人国产精品| 99久久免费国产特黄|