• <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 閱讀(142) 評論(0)  編輯 收藏 引用
            97久久超碰国产精品旧版| 久久综合九色综合久99| 少妇内射兰兰久久| 久久久久久无码Av成人影院| 久久国产免费观看精品| 欧美性大战久久久久久| 亚洲国产精品成人久久| 一本一道久久精品综合| 99久久精品国产一区二区| 国产精品99久久精品| 97视频久久久| 久久国产精品视频| …久久精品99久久香蕉国产 | 97久久婷婷五月综合色d啪蜜芽| 97精品依人久久久大香线蕉97| 色综合合久久天天综合绕视看| 久久久国产亚洲精品| 久久综合五月丁香久久激情| 狠狠色丁香久久婷婷综合五月| 成人综合久久精品色婷婷| 国产三级精品久久| 香港aa三级久久三级| 国产一级持黄大片99久久| 亚洲香蕉网久久综合影视| 欧美大战日韩91综合一区婷婷久久青草| 99久久婷婷国产综合亚洲| 色8久久人人97超碰香蕉987| 久久人与动人物a级毛片| 一本大道久久东京热无码AV| 久久精品国产黑森林| 久久男人中文字幕资源站| 青青草国产精品久久| 久久综合九色综合欧美狠狠| 青青国产成人久久91网| 国产精品美女久久久| 久久精品国产福利国产秒| 国产综合成人久久大片91| 超级碰久久免费公开视频| 久久天天躁狠狠躁夜夜2020老熟妇 | 久久综合久久综合亚洲| 日本高清无卡码一区二区久久 |