• <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>
            posts - 24,  comments - 0,  trackbacks - 0
            今天刷了3道字典樹
            hdu 1251 1075  1247
            摸板
             1 #include<cstdio>
             2 #include<cstring>
             3 #include<algorithm>
             4 #include<iostream>
             5 using namespace std;
             6 typedef struct node{
             7    int cnt;
             8    struct node *b[26];
             9    void init()
            10    {//printf("bsdfjihsd\n");
            11        memset(b, 0sizeof(b));
            12        cnt = 0;
            13    }
            14 }Tree;
            15 Tree tree[500000];
            16 int cnt = 0;
            17 Tree *root = NULL;
            18 void init()
            19 {
            20     cnt = 0;
            21     root = &tree[cnt++];
            22     root->init();
            23 }
            24 void insert(char* p)
            25 {
            26     node* q = root;
            27     while(*p)
            28     {
            29         int idx = *- 'a';
            30         if(0 == q->b[idx])
            31         {
            32             q->b[idx] = &tree[cnt++];
            33             q->b[idx]->init();
            34         }
            35         q->b[idx]->cnt++;
            36         q = q->b[idx];
            37         p++;
            38     }
            39 }
            40 
            41 int query(char* p)
            42 {
            43     node* q = root;
            44     int ans = 0;
            45     while(*p)
            46     {
            47         int idx = *- 'a';
            48         if(0 == q->b[idx])
            49         {
            50             ans = 0;
            51             return 0;
            52         }
            53         ans = q->b[idx]->cnt;
            54         q = q->b[idx];
            55         p++;
            56     }
            57     return ans;
            58 }
            59 int main()
            60 {
            61     //freopen("in.txt", "r", stdin);
            62     char s[20];
            63     init();
            64     while(gets(s))
            65     {
            66 
            67 
            68         if(strcmp(s,"\0"== 0){break;}
            69         insert(s);
            70     }
            71     while(scanf("%s",s) != EOF)
            72     {
            73         int ans  = query(s);
            74         printf("%d\n",ans);
            75     }
            76     return 0;
            77 }
            78 
            posted on 2011-09-13 20:28 ACSeed 閱讀(135) 評論(0)  編輯 收藏 引用
            <2011年9月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            常用鏈接

            留言簿(1)

            隨筆檔案

            偶像的Blog

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品tv久久久久久久久久| 一本久道久久综合狠狠爱| 久久精品人人做人人爽97| 久久精品无码一区二区WWW| 久久久久久伊人高潮影院 | 国产伊人久久| 精品国产99久久久久久麻豆| 久久精品国产亚洲AV蜜臀色欲| 97久久婷婷五月综合色d啪蜜芽| 久久国产乱子伦免费精品| 99热成人精品免费久久| 亚洲精品无码久久久久| 久久99热精品| 狠狠干狠狠久久| 亚洲第一极品精品无码久久| 久久无码一区二区三区少妇| 韩国无遮挡三级久久| 亚洲天堂久久久| 久久久艹| 色婷婷噜噜久久国产精品12p| 久久精品国产亚洲精品2020| 久久免费香蕉视频| 少妇人妻综合久久中文字幕| 久久成人18免费网站| 久久亚洲国产精品五月天婷| 久久精品国产99国产电影网 | 欧美亚洲国产精品久久久久| 九九热久久免费视频| 久久久久久A亚洲欧洲AV冫| 久久精品亚洲精品国产欧美| 久久亚洲中文字幕精品一区| 久久精品国产精品亚洲精品| 午夜精品久久久久久久| a高清免费毛片久久| 久久国产成人精品麻豆| 蜜臀久久99精品久久久久久| 亚洲AV无码一区东京热久久| 国产精品久久网| 久久人人爽人人爽人人爽| 久久99国产精品久久99果冻传媒 | 午夜福利91久久福利|