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

            hdu 1251

             

            統(tǒng)計難題

            Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)
            Total Submission(s): 9806    Accepted Submission(s): 3949


            Problem Description
            Ignatius最近遇到一個難題,老師交給他很多單詞(只有小寫字母組成,不會有重復(fù)的單詞出現(xiàn)),現(xiàn)在老師要他統(tǒng)計出以某個字符串為前綴的單詞數(shù)量(單詞本身也是自己的前綴).
             


             

            Input
            輸入數(shù)據(jù)的第一部分是一張單詞表,每行一個單詞,單詞的長度不超過10,它們代表的是老師交給Ignatius統(tǒng)計的單詞,一個空行代表單詞表的結(jié)束.第二部分是一連串的提問,每行一個提問,每個提問都是一個字符串.

            注意:本題只有一組測試數(shù)據(jù),處理到文件結(jié)束.
             


             

            Output
            對于每個提問,給出以該字符串為前綴的單詞的數(shù)量.
             


             

            Sample Input
            banana band bee absolute acm ba b band abc
            Sample Output
            2 3 1 0


            每天學(xué)點新東西
            今天學(xué)了點trie,以前只聞其名,未曾寫過,今天自習(xí)看了看,貌似不難
            照著ac自動機(jī)的模版寫了第一個trie的程序(囧),1Y




            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;

            struct node
            {
                
            int next[26];
                
            int x;
                
            int count;
                
            void init()
                
            {
                    memset(next,
            -1,sizeof(next));
                    count
            =0;
                }

            }
             s[5000005];
            int ind,sind;
            void cas_init()
            {
                s[
            0].init();
                sind
            =1;
            }

            void ins(char str[])
            {
                
            int len=strlen(str);
                
            int i,j,ind;
                
            for(i=ind=0;i<len;i++)
                
            {
                    j
            =str[i]-'a';
                    
            if(s[ind].next[j]==-1)
                    
            {
                        s[sind].init();
                        s[ind].next[j]
            =sind++;
                    }

                    s[ind].count
            ++;
                    ind
            =s[ind].next[j];
                }

                s[ind].count
            ++;
            }

            int search(char str[])
            {
                
            int ind,i,j,len=strlen(str);
                ind
            =0;
                
            for(i=0;i<len;i++)
                
            {
                    j
            =str[i]-'a';
                    
            if(s[ind].next[j]==-1)
                        
            return 0;
                    
            else ind=s[ind].next[j];
                }

                
            return s[ind].count;
            }

            int main()
            {
                
            char str[15];
                
            int num;
                cas_init();
                
            while(gets(str)&&str[0]!='\0') ins(str);
                
            while(gets(str))
                
            {
                    num
            =0;
                    num
            =search(str);
                    printf(
            "%d\n",num);
                }

                
            return 0;
            }






            就是這個hdu1251


            posted on 2012-07-15 23:22 jh818012 閱讀(170) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標(biāo)題查看
            • --王私江
            欧美精品乱码99久久蜜桃| 久久r热这里有精品视频| 久久精品国产第一区二区三区| 欧美精品丝袜久久久中文字幕 | 国产精品久久久久…| 久久久国产精品福利免费| 国产精品久久久久久久久免费 | 热久久这里只有精品| 欧美亚洲国产精品久久| 99久久久精品免费观看国产| 免费无码国产欧美久久18| 国产精品美女久久福利网站| 国产精品一区二区久久精品涩爱| 亚洲午夜久久久久妓女影院| 国产精品久久久久9999| 久久青青草原精品国产软件| 一本久道久久综合狠狠躁AV| 久久综合狠狠综合久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久综合中文字幕| 久久精品国产亚洲Aⅴ香蕉 | 国产精品欧美久久久久天天影视| 精品久久无码中文字幕| 狠狠综合久久综合中文88| 久久亚洲欧洲国产综合| 欧美一级久久久久久久大| 色欲久久久天天天综合网精品| 精品无码久久久久久久动漫| 色综合久久综精品| 久久国产精品一区二区| 国内精品伊人久久久久av一坑| 久久国产免费直播| 久久午夜无码鲁丝片秋霞 | 国产精品久久亚洲不卡动漫| 久久婷婷五月综合97色| 欧美日韩精品久久久久| 国产99久久久国产精品小说| 香港aa三级久久三级老师2021国产三级精品三级在 | 69久久夜色精品国产69| 久久久久亚洲AV无码麻豆| 亚洲va中文字幕无码久久不卡|